JsonDiff is helpful if you have two versions of an object, and want to know if some attributes have changed, and if so which ones. For simple object types with 5-10 attributes Action Script might suffice, but if you have complex, nested structures, it's not fun. That's where JsonDiff can help. Just convert both versions to their JSON representation using classToJson(), and let JsonDiff find the differences. The output is a JSON array of changes that need to applied to get the latter version from the former (see below).
What is a RFC 6902 JSON Patch?
If we had two JSON documents
{"a": 0,"b": [1,2]}
{"b": [1,2,0]}
the patch to obtain b from a was
[{"op":"move","from":"/a","path":"/b/2"}]
|
|
|
|---|
Operation Signatures
JsonDiff offers the following base operations:
-
calcDiff
-
calcDiffExcept
-
applyDiff
-
isEmptyDiff
(a convenience method for testing a calculated diff for being "empty", meaning the two JSONs are equal)
Synopsis
Suppose you have an xUML class A, and two instances a1 and a2 with JSON representations js1=a1.classToJson() and js2=a2.classToJson(). Then the following is true:
-
applyDiff(js1, calcDiff(js1, js2)) == js2-
calcDiff(js1, js2)=>js12diff(see example section below) -
applyDiff(js1, js12diff)=>jsx, with jsx == js2
-
-
isEmptyDiff(calcDiff(js1, js1)) == true -
calcDiffExcept(js1, js2, ignoredAttributes[])behaves like calcDiff, but will not report difference in attributes that are explicitly ignored (the e2e-type attribute sometimes generated by classToJson() is ignored automatically). -
the "normalized" parameter steers whether ADD/REMOVE pairs of the same object are normalized to MOVE (usually recommended with structures containing arrays)
Related Pages:
-
JsonMatch
Testing JSON strings or object instances for matching against a DSL (Domain Specific Language) similar toWHEREclauses in SQL. -
JsonNode
Parse and manipulate arbitrary JSON strings, without the need to create a class representation for it. -
https://scheer-pas-doc.atlassian.net/wiki/x/vYCRJQ
Find and extract parts of JSON object based on JsonPath queries. -
JsonPointer
Extract part of JSON object using a JsonPointer (such as returned as part of a patch from JsonDiff). -
Json Schema
Convert a JSON schema file to an XSD, ready to be imported into the PAS Builder. -
https://scheer-pas-doc.atlassian.net/wiki/x/koGRJQ
Generate SQL statements from JSON objects.
Related Documentation:
-
-
classToJson()
Takes any object or array of objects and tries to map it to a JSON string.
-