First: I'm aware of other solutions like Removing unused information from JSON but I'm looking for a more dynamic approach.
I have two json objects. The first one looks like this:
{
"key2":"value2",
"key3":{
"key4":"value4",
},
"key6":"value6",
}
And the second json objects looks like this:
{
"key1":"value1",
"key2":"value2",
"key3":{
"key4":"value4",
"key5":"value5"
},
"key6":"value6"
}
Is there a dynamic approach (java or javascript) to ensure that only the matching keys between both json objects are returned? In this case, key1 and key5 should be deleted from the second json because this keys are not present in the first one, but the first array does not always look the same.