python newbie:
json1.json
{
"key1": {
"s11": 1,
"s12": 2,
"s13": "abc"
},
"key2": {
"s21": [1, 2, 3, 4],
"s22": {
"s221": {
"s2211": "abc"
}
}
},
"key3": "name1"
}
json2.json
{
"key1": {
"p12": 2,
"p13": "abc",
"s11": 1
},
"key2": {
"ps22": {
"ps221": {
"ps2211": "abc"
}
},
"ps21": ["1", "2", "3", "4"],
"ps23" : "abc",
"ps24":1,
"s21": [1,2,3,4]
}
}
I am trying to compare the two json object names; json1.json and json2.json and want to list out the difference in the object names
eg., list out the below differences
1. key3 is missing from json2 that is present in json1 --> Got this with below code
2. key2.s22 is changed to key2.ps22 and key1.s12 to key1.p12
3. will not bother the key2.s22.s221.s2211 different to key2.ps22.ps221.ps2211 as want to capture initial hierarchical differences
Can someone please help me with the appropriate methods or commands to capture these differences?
I could get the differences in the object names with below code.
d1=json.load(open("json1.json"))
d2=json.load(open("json2.json"))
s1=set(d1.keys()) - set(d2.keys())
print(s1)
o/p -> {'key3'}
but my requirement is to get the difference in the next level hierarchy i.e.,
key2.s22 is changed to key2.ps22
key2.s21 is changed to key2.ps21