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 -
<groupId>com.flipkart.zjsonpatch</groupId>
<artifactId>zjsonpatch</artifactId>
<version>{version}</version>
JsonNode 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 -
add
remove
replace
move
copy
JsonNode 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, the source
JSON is unmodified and can be used further).
EnumSet<DiffFlags> flags = DiffFlags.dontNormalizeOpIntoMoveAndCopy().clone()
JsonNode patch = JsonDiff.asJson(JsonNode source, JsonNode target, flags)
First Json
{"a": 0,"b": [1,2]}
Second json ( the json to obtain )
{"b": [1,2,0]}
Following patch will be returned:
[{"op":"move","from":"/a","path":"/b/2"}]
here "op"
specifies the operation ("move"
), "from"
specifies the path from where the value should be moved, and "path"
specifies where value should be moved. The value that is moved is taken as the content at the "from"
path.
JsonPatch.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.
Can you improve this documentation? These fine people already did:
Gopi Vishwakarma, vishwakarma, Dan Douglas, David Banks, Santiago Castro, Hans Joachim Desserud, Daniel Shmuglin, The Gitter Badger, Pratyush Verma & VishwakarmaEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close