Before any one marks this as duplicate, i've already checked this question: Remove duplicates and merge JSON objects. (copied example from there)
I'm working in on a case that involves merging json like in the example below,
[{
"id" : 1,
"name" : "abc",
"nodes" :[
{
"nodeId" : 20,
"nodeName" : "test1"
}
]
},
{
"id" : 1,
"name" : "abc",
"nodes" :[
{
"nodeId" : 21,
"nodeName" : "test2"
}
]
}]
to something like till the leaf nodes,
[{
"id" : 1,
"name" : "abc",
"nodes" :[
{
"nodeId" : 20,
"nodeName" : "test1"
},
{
"nodeId" : 21,
"nodeName" : "test2"
},
]
}]
I can use the brute force method by recursively comparing nodes and merging manually into an object and finally converting to a json string. I was wondering if there is a better way to do it using json4s. More context, It's a scala project, there are 1000s of json that are to be merged into one and they may have nested complext structes like array and object.
Merging here means adding to pre existing data on duplicate nodes not overwriting them, as in example above.
I've also considered using trees, but not much progress there.