Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Alternative approach for schema free delta report.

Problem Statement

The problem with 2nd Delta API is that it needs to compare any JSON payload to data stored under an anchor. This JSON payload can be coming from any source and regardless of its schema a delta should be generated between the payload and the data under the anchor.

The preferable approach here would be to parse the JSON payload into DataNodes and then compare the generated DataNodes against the DataNodes under the anchor. This would allow us to have a delta report which is in line with CPS and would enable us to provide crucial detail about the data nodes that is their xpath.

But since the second API accepts any JSON string as an input, one cannot be always sure that the payload will have the same schema as the anchor. And hence the approach of parsing to DataNodes can only happen when the schemas are identical.

In cases where schemas are not identical, there as soon as we attempt to parse the payload to DataNode, CPS will throw an exception terminating the parsing.

The most feasible alternative is to make use of JSON Nodes along with JSON path. Where JSON Nodes and JSON Path are used as a replacement for DataNodes and xPaths respectively.

Use of JSON Nodes and JSON Path

...

Once this is done a separate algorithm will be used to find the delta between JSON Nodes.

JSON Path

The most suitable candidate to be used as replacement for xpath are JSON path, a sample JSON path looks like this: 

Code Block
$.store.book[0].title

Here:

  • $ symbol refers to the root object or element.
  • . operator is the dot-child operator, which you use to denote a child element of the current element.
  • [ ] is the subscript operator, which you use to denote a child element of the current element (by name or index).

In order to utilize the JSON Path a new algorithm will need to be implemented to generate JSON paths from the available JSON Nodes.

Also, the existing delta algorithm can then be modified and reused for JSON path and JSON nodes.

Note
Note: Open for suggestions for alternative approaches

...