3

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
  }
]
lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20
Vivek Narayanasetty
  • 522
  • 2
  • 5
  • 12
  • I don't know about zjsonpatch but it looks like you could just convert the output yourself into the way you want? Loop and make a new json object for each field, adding the same data to each (while adding field to path). – vakio Aug 05 '21 at 17:07
  • 2
    Thanks @Vakio for the suggestion. Yes, I have done the same but looking if there is any function/parameter which can be passed to the API and achieve the same functionality. – Vivek Narayanasetty Aug 09 '21 at 05:53

0 Answers0