Sunday 18 November 2018

JSON-Patch: Applying deltas to JSON Documents in Swift

I recently started looking at saving bandwidth between a client and server that communicates with JSON. Some of these messages send large JSON documents that do not change very frequently and when there are changes, they are small relative to the whole document. My search lead me to JSON-Patch  a IETF proposed standard (RFC 6902).  JSON-Patch is a patch format which itself is specified in JSON, it can perform operations on a target JSON document to transform it to the intended state. The standard has the following operations: -

  • add - Insert / Replace a value at the given location with a new value.
  • remove - Remove a value at the given location (value must exist).
  • replace - Replace a value at the given location with a new value (value must exist).
  • move - Move a value at the given location to a new location. Logically equivalent to a remove then add. (value must exist)
  • copy - Copies a value at the given location to a new location (value must exist).
I looked for implantations of JSON-Patch in Swift, and found one but it had dependences on SwiftlyJSON another swift module. Which is great if you're already using it in your project, but I wanted to work with the JSONSerialization that comes in Foundation directly. So I wrote my own JSONPatch swift module. This initial version can only apply patches, it does not currently generate patches based on two JSON documents. Project available here on GitHub.

Usage

JSONPatch can work with the Data representations of JSON.
However if you are already parsing the JSON with JSONSerialization within your project then JSONPatch can work with the parsed objects you already have. This can be especially useful if you want to apply a patch relative to sub-element of the whole JSON document.

8 comments:

  1. I need to communicate my deference of your composing aptitude and capacity to make perusers read from the earliest starting point as far as possible. I might want to peruse more up to date presents and on share my musings with you.

    360DigiTMG

    ReplyDelete
  2. This post is incredibly simple to examine and recognize without disregarding any nuances. Inconceivable work!

    hrdf scheme

    ReplyDelete
  3. It is the expect to give noteworthy information and best takes a shot at, including a perception of the regulatory cycle.
    https://360digitmg.com/course/certification-program-in-data-science

    ReplyDelete
  4. an extremely wonderful post this is. Genuinely, perhaps the best post I've at any point seen to find in as long as I can remember. Goodness, simply keep it up.
    what is hrdf claimable

    ReplyDelete
  5. This is a great motivational article. In fact, I am happy with your good work. They publish very supportive data, really. Continue. Continue blogging. Hope you explore your next post
    HRDF training

    ReplyDelete
  6. Great post, you have pointed out some fantastic points , I likewise think this s a very wonderful website. Driver license

    ReplyDelete
  7. I'm cheerful I found this blog! Every now and then, understudies need to psychologically the keys of beneficial artistic articles forming. Your information about this great post can turn into a reason for such individuals.
    cyber security course in malaysia

    ReplyDelete
  8. The patches that engine cycle clubs utilize nowadays will indicate rank and position inside the club as well as the club that the biker has a place with. visit this page

    ReplyDelete