I have a json file with 20 objects. Some of the objects have duplicate key/value pairs or only values. I want to remove those objects and add them to a new object "common".
This is an example of three json objects:
{
"object1": {
"city": "Lazy Town",
"country": "Fallador",
"salutation": "Dear"
},
"object2": {
"name": "The five",
"city": "Ghost Town",
"school": "Fallador"
},
"object3": {
"name": "The five",
"stad": "Ghost Town",
"country": "Fallador",
"salutation": "Dear"
}
}
I want to achieve the following:
{
"common" : {
"city" : "Ghost Town",
"country": "Fallador",
"salutation" : "Dear"
},
"object1": {
"city": "Lazy Town"
},
"object2": {
"name": "The five",
"city": "Ghost Town"
},
"object3": {
"name": "The five",
"stad": "Ghost Town"
}
}
I need to compare the values only, as you can see the keys could contain the same value but keyname can be different.
Can someone advise me how I can achieve this? With an example if possible in C#, Java, Python or any other language.
Thanks in advance!