I have two json datas as
json_1 = [{'purchasedPerson__id': 2, 'credit': 3000}, {'purchasedPerson__id': 4, 'credit': 5000}]
json_2 = [{'purchasedPerson__id': 1, 'debit': 8526}, {'purchasedPerson__id': 4, 'debit': 2000}]
i want to merge both the json and needed optput as
json_final = [{'purchasedPerson__id': 2, 'credit': 3000 , 'debit'=0},
{'purchasedPerson__id': 4, 'credit': 5000 , 'debit'=2000},
{'purchasedPerson__id': 1, 'credit'=0, 'debit': 8526}]
how the above method can be done
3
Answers
This is a case where
pandas
can be very convenient. By converting to dataframes and merging on "purchasedPerson__id", you will get the desired output:Output: