zjsonpatch diff results in a flat format for add operation

502 Views Asked by At

I am trying to get the JSON diff using the zjsonpatch library. The library provides the results for add, remove and replace operations. The results are coming as expected.

But for add operation, the values output is sometimes a map of key/value pairs like below. In this case, the path is also an array element.

{
  "op": "add",
  "path": "/Entity1/0/Entity2/Entity3/2",
  "value": {
    "Field1": "ABC",
    "Field2": "BBC",
    "Field3": 999
  }
}

Is it possible to get output in a flat structure for each field? like below

[
  {
    "op": "add",
    "path": "/Entity1/0/Entity2/Entity3/2/Field1",
    "value": "ABC"
  },
  {
    "op": "add",
    "path": "/Entity1/0/Entity2/Entity3/2/Field2",
    "value": "BBC"
  },
  {
    "op": "add",
    "path": "/Entity1/0/Entity2/Entity3/2/Field3",
    "value": 999
  }
]
0

There are 0 best solutions below