Find a json object with the coordenates

21 views Asked by At

I want to create a list of Json object from a big Json file using the coordenates obtained from jsondiff,

E.g. [from the following code we get the location of the Json object with the following format "{'user': {'actions': {0: {'description': 'blablabla123'}}}}"], is there a way or maybe a library in python to find the json objet based on the output?

import jsondiff

json1 = {
    "user":
    {
            "actions":
             [
                 {
                 "name": "reading",
                 "description": "blablabla"
                 }
             ],
            "name": "John"
    }
}

json2 = {
    "user":
    {
            "actions":
             [
                 {
                 "name": "reading",
                 "description": "blablabla123"
                 }
             ],
            "name": "John"
    }
}

difference_json1 = jsondiff.diff(json1, json2)

print(difference_json1)

####### output = {'user': {'actions': {0: {'description': 'blablabla123'}}}}######## 

I tried to get the keys recursively to print the object, E.g 
however I think there should be a better way to get this information


for i in difference_json1.keys():
    ii = difference_json1[i]
    try:
        for x in ii:
            try:
                xx = difference_json1[i][x]
                for y in xx.keys():
                    print(json1[i][x][y])
            except:
                print(json1[i][x])
    except:
        print(json1[i])
0

There are 0 answers