I would like to compare two JSON Objects and return another object with only the properties missing in one JSON Object. For example:
json1 = {
"name": "ABCD",
"hobbies": [
{
"water_hobby1": "Rafting",
"water_hobby2": "swimming",
},
{
"hobby3": "Singing",
"hobby4": "Drawing",
}
]
}
json2 = {
"name": "ABCD",
"hobbies": [
{
"hobby3": "Singing",
"hobby4": "Drawing",
}
]
}
Expected output:
json = {
"hobbies": [
{
"water_hobby1": "Rafting",
"water_hobby2": "swimming",
},
]
}
Lets say I write json1.getDiff(json2); I want the resulting json to contain only the properties that are missing in json2 and present in json1. The nesting of properties and properties themselves is dynamic.
My actual JSOn is like below:
{
"property1": 0,
"property2": "value1",
"property3": [
{
"name": "value2",
"property4": [
{
"property5": 0,
"name": "value3",
"porperty6": 0,
"property7": [
{
"name": "",
"property": 0,
"property": value,
"property": "value",
"property": "value",
"property": "value"
},
{
"name": "",
"property": 0,
"property": value,
"property": "value",
"property": "value",
"property": "value"
},
{
"name": "",
"property": 0,
"property": value,
"property": "value",
"property": "value",
"property": "value"
},
{
"name": "",
"property": 0,
"property": value,
"property": "value",
"property": "value",
"property": "value"
},
{
"name": "",
"property": 0,
"property": value,
"property": "value",
"property": "value",
"property": "value"
},
{
"name": "",
"property": 0,
"property": value,
"property": "value",
"property": "value",
"property": "value"
},
{
"name": "",
"property": 0,
"property": value,
"property": "value",
"property": "value",
"property": "value"
},
{
"name": "",
"property": 0,
"property": value,
"property": "value",
"property": "value",
"property": "value"
}
]
},
{
Many Such Objects With nested array and objects
}]
},
{
"name": "value",
"property4": []
}
}
Suppose my source JSON Contains Property7[0] Object but my another JSON object does not contain Property7[0] object. I want to only return Property7[0] as my output. The code I am following returns the whole Property7 array which obviously does not contain property7[0] object. But that is not I want. The code is not looping through the objects in the array Property7. some help for me to achieve this is what I seek.