3

I have two json files as such:

json1

     {
    "plans": {
      "buildings": [
        {
          "floors": ["1" "2" "3" ]
        },
        {
          "floors": ["1"]
        }
      ]
  }
}

json 2

 { "plans": {
          "buildings": [
            {
              "floors": ["3" "5" "6" ]
            },
            {
              "floors": []
            }
          ]
      }
    }

Required json after merge union

 {
    "plans": {
      "buildings": [
        {
          "floors": ["1","2","3","5","6" ]
        },
        {
          "floors": ["1"]
        }
      ]
  }
}

How to achieve this operation by getting json diff and merge patching using available tools.I dont want to loop through each and every child nodes and check manually.

mohd.gadi
  • 495
  • 1
  • 7
  • 15

2 Answers2

0

I have similar problem same as you too. My solution is use JSON patch to make patch from diffed JSON then send patch to apply at another system. Look for more information at http://jsonpatch.com/. They provide repository that have library for each programming language.

EThaiZone
  • 311
  • 1
  • 8
0

I created a light api for diff and merge for these scenarios. Open source: https://github.com/ryanshane/JsonDiffMerge

For the arrays, they don't have a primary key so you will end up with duplicate entries unless you changed the array of strings to objects eg [{ id: "uid string", value: "3" }] instead of ["3"].

Shane
  • 303
  • 2
  • 9