...
There are several ways of representing the differences between JSON but here we discuss the JSON Patch format of representing these differences because the proposed Delta report closely represents JSON patch with a few differences. This approach focuses in producing another JSON document that represents the differences between the two JSON's that have been compared.
RFC 6902 JSON Patch
JSON Patch defines a JSON document structure for expressing a sequence of operations to apply to a JavaScript Object Notation(JSON) document; it is suitable for use with the HTTP PATCH method. The "application/json-patch+json" media type is used to identify such patch documents.
...
Code Block | ||||
---|---|---|---|---|
| ||||
[
{ "op": "test", "path": "/a/b/c", "value": "foo" },
{ "op": "remove", "path": "/a/b/c" },
{ "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] },
{ "op": "replace", "path": "/a/b/c", "value": 42 },
{ "op": "move", "from": "/a/b/c", "path": "/a/b/d" },
{ "op": "copy", "from": "/a/b/d", "path": "/a/b/e" }
] |
RFC 9144 Data Model
RFC 9144 YANG data model that defines RPCs intended to be used in conjunction with NETCONF [RFC6241] or RESTCONF [RFC8040]. These RPCs allow a client to request a server to compare two NMDA datastores and report any differences.
Comparison of RFC 9144 Data Model and RFC6902 JSON Patch format
- The core of the RFC 9144 solution is a new management operator, <compare>, that compares the data tree contents of two datastores. The operation checks whether there are any differences in values or in data nodes that are contained in either datastore and returns any differences as output. The output is returned in the format specified below.
- The RFC6902 approach to Delta report generation follows the JSON patch format. A JSON Patch document represents an array of objects, where each object contains exactly one operation, path and associated values. The operation can have following values: add, remove, replace, move, copy and test. The path represents the JSON patch and the values contain the difference in source and target values.
|
|
---|
CPS Delta Report Format
Based on the RFC documentations mentioned above, CPS Delta Report is designed in the format specified in the following code block. This Delta Report takes the features from both RFCs that are best suited for CPS and fulfill it's requirements.
Code Block | ||||
---|---|---|---|---|
| ||||
[
{
"action": "ADD",
"xpath": "/bookstore/categories/[@code=3]",
"target-data": {
"code": "3,",
"name": "kidz"
}
},
{
"action": "REMOVE",
"xpath": "/bookstore/categories/[@code=1]",
"source-data": {
"code": "1,",
"name": "Fiction"
}
},
{
"action": "UPDATE",
"xpath": "/bookstore/categories/[@code=2]",
"source-data": {
"name": "Funny"
},
"target-data": {
"name": "Comic"
}
}
] |
Proposed Algorithm
The JSON data stored in CPS can be retrieved as Maps, And using this we can find the delta between two anchors retrieved as two separate Maps. The result can be stored in an JSON array with appropriate notations for action, xpath and payload. The following algorithm can be used to find the difference between the two maps and also recursively finds the difference between the child data nodes. The response is in form of a JSON Array which closely represents the JSON Patch format as described above.
...