Name: zjsonpatch
Owner: Flipkart Incubator
Description: This is an implementation of RFC 6902 JSON Patch written in Java
Created: 2014-11-17 17:23:43.0
Updated: 2018-01-19 10:52:17.0
Pushed: 2018-01-07 16:29:55.0
Size: 228
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Package | Class, % | Method, % | Line, % | ————-|—————|—————–|——————–| all classes | 100% (6/ 6) | 93.6% (44/ 47) | 96.2% (332/ 345) |
Add following to <dependencies/>
section of your pom.xml -
upId>com.flipkart.zjsonpatch</groupId>
ifactId>zjsonpatch</artifactId>
sion>{version}</version>
Node patch = JsonDiff.asJson(JsonNode source, JsonNode target)
Computes and returns a JSON Patch from source to target, Both source and target must be either valid JSON objects or arrays or values. Further, if resultant patch is applied to source, it will yield target.
The algorithm which computes this JsonPatch currently generates following operations as per rfc 6902 -
Node target = JsonPatch.apply(JsonNode patch, JsonNode source);
Given a Patch, it apply it to source Json and return a target json which can be ( json object or array or value ). This operation performed on a clone of source json ( thus, source json is untouched and can be used further).
Set<DiffFlags> flags = DiffFlags.dontNormalizeOpIntoMoveAndCopy().clone()
Node patch = JsonDiff.asJson(JsonNode source, JsonNode target, flags)
First Json
: 0,"b": [1,2]}
Second json ( the json to obtain )
": [1,2,0]}
Following patch will be returned:
p":"MOVE","from":"/a","path":"/b/2","value":0}]
here 'op' represents Operation, 'from' represent path from where value should be moved, 'path' represents where value should be moved and value represents value to move.
Patch.applyInPlace(JsonNode patch, JsonNode source);
Given a patch
, it will apply it to the source
JSON mutating the instance, opposed to JsonPatch.apply
which returns
a new instance with the patch applied, leaving the source
unchanged.