apply changes to a json

99 Views Asked by At

so let us suppose i have a

json1 = {
"accounting" : 
{ "firstName" : "John",  
"lastName"  : "Doe",
"age"       : 23 },

                     { "firstName" : "Mary",  
                       "lastName"  : "Smith",
                        "age"      : 32 }
                 ],                            

"sales"      : 
{ "firstName" : "Sally",
"lastName"  : "Green",
"age"      : 27 },

                     { "firstName" : "Jim",   
                       "lastName"  : "Galley",
                       "age"       : 41 }
                 ] 

}


and i have made some changes to this json and stored it as a separate json

json2 = {
"accounting" : [  
{ "firstName" : "John",  
"lastName"  : "Doe",
"age"       : 23 },

                     { "firstName" : "Mary",  
                       "lastName"  : "Smith",
                        "age"      : 32 }
                     
                     { "firstName" : "Steve",  
                       "lastName"  : "John",
                        "age"      : 30 }
    
    
                 ],                            

"sales"      :
{ "firstName" : "Sally",
"lastName"  : "Green",
"age"      : 30 },

{ "firstName" : "Jim",  
"lastName"  : "Galley",
"age"       : 41 }

}

so now i want to find the difference between the two json and apply the changes to the first json as well . so basically i want to convert first into the second by only applying the changes to it

*this problem actually is part of a bigger problem that i am trying trying to solve . so the method of completely replacing the first json with second will not help(json1==json2 )

the json files i am dealing with are 800 lines with 6 to 7 levels of nesting and multiple lists of objects so to manually write a code will also not help

i would prefer the code in python and js would be fine as well. i used json diff and patch in js that made changes but at the wrong indices . and i have not tried it with a big data like mine also tried jsondiff python which gives the changes and differences but dont know how to apply changes to the original json .

your text

0

There are 0 best solutions below