I have 2 json files. "original.json" and "changed.json", and also have 2 systems and each systems have "original.json". In my other codes, if user modify json file, then will save changed json files as "changed.json". So, I want compare "original.json" and "changed.json" to figure out diffences between 2 json files and save that differences as "result.json". So, in other systems, I want it to apply changes to its "original.json" to make same with other system's "original.json".
Or if there are any better way, please let me know.
"original.json"
{
"ToDoList": {
"Task1": {
"Date": "20230613",
"Name": "Daniel",
"Description": "a"
}
},
"Contacts": {
"Contact_1": {
"Name": "Daniel",
"Office": "8F C03"
},
"Contact_2": {
"Name": "Michael",
"Office": "10F A12"
}
}
}
"changed.json"
{
"ToDoList": {
"Task1": {
"Date": "20230613",
"Name": "Daniel",
"Description": "a"
}
},
"Contacts": {
"Contact_1": {
"Name": "Daniel",
"Office": "8F C03"
}
}
}
I tried to compare 2 json files by using jsondiff.
differences = jsondiff.diff(original_data, changed_data, dump=True)
result_json_name = f"result_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
result_path = os.path.join(target_path, result_json_name)
with open(result_path, 'w') as file:
json.dump(differences, file)
And I don't have any idea to apply changes by merging "original.json" and "result.json"