I am aware of this post: Java - Merge JSON files ... but my problem is a bit different.
Let's say I have two JSON objects. First:
{
"nodes":
[
{
"id": "Main",
"children":
[
{
"id": "C1",
"children":
[
{
"id": "C1.1",
"children":
[]
}
]
}
]
}
]
}
Second:
{
"nodes":
[
{
"id": "Main",
"children":
[
{
"id": "C2",
"children":
[
{
"id": "C2.1",
"children":
[]
}
]
},
{
"id": "C3",
"children":
[
{
"id": "C3.1",
"children":
[]
}
]
}
]
}
]
}
And I would expect result to look like this:
{
"nodes":
[
{
"id": "Main",
"children":
[
{
"id": "C1",
"children":
[
{
"id": "C1.1",
"children":
[]
}
]
},
{
"id": "C2",
"children":
[
{
"id": "C2.1",
"children":
[]
}
]
},
{
"id": "C3",
"children":
[
{
"id": "C3.1",
"children":
[]
}
]
}
]
}
]
}
Basically, I have multiple objects where "Main" node is constant but underneath there can be random number of different children and each child can have its own children.
I would like the code to produce one big object where parts duplicated across multiple objects are reduced to one.
Maybe there is a library that could do that for me? Maybe someone knows a simple solution for that...?
Thanks in advance for answers, I've been struggling to make this one work. There is probably too much code to post here and still is doesn't work correctly for every scenario.