I have loaded two json files in Python3.8, and I need to merge the two based on a condition.
Obj1 = [{'account': '223', 'colr': '#555555', 'hash': True},
{'account': '134', 'colr': '#666666', 'hash': True},
{'account': '252', 'colr': '#777777', 'hash': True}]
Obj2 = [{'sn': 38796, 'code': 'df', 'id': 199, 'desc': 'jex - #777777- gg2349.252'},
{'sn': 21949, 'code': 'se', 'id': 193, 'desc': 'jex - #555555 - gf23569'},
{'sn': 21340, 'code': 'se', 'id': 3, 'desc': 'jex - #666666 - gf635387'}]
# What I am trying to get
Obj3 = [{'sn': 38796, 'code': 'df', 'id': 199, 'desc': 'jex - #777777- gg2349.252', 'account': '252', 'colr': '#777777', 'hash': True},
{'sn': 21949, 'code': 'se', 'id': 193, 'desc': 'jex - #555555 - gf23569', 'account': '223', 'colr': '#555555', 'hash': True},
{'sn': 21340, 'code': 'se', 'id': 3, 'desc': 'jex - #666666 - gf635387', 'account': '134', 'colr': '#666666', 'hash': True}]
I have tried from what I can gather everything on SO from append, extend etc but I fall short on the condition.
I need to be able to append elements in Obj1 to Obj2 at their correct place based on a condition that if the colr of Obj1 is mentioned in desc of Obj2 it should append that whole element from Obj1 into the correlated element of Obj2. Or create a new Obj3 that I can print these updated values from.
What I have tried and looked at thus far Append JSON Object, Append json objects to nested list, Appending json object to existing json object and a few others that also didn't help.
Hope this makes sense and thank you