Compare json files

278 Views Asked by At

I have two json files.

File1.json File2.json

Using python, I want to compare both files and write differences in third file Output.json

Output file should be easy to read.

1

There are 1 best solutions below

1
Ashe Muller On BEST ANSWER

Should do what you're looking for, assuming I read the question right.

import json

data1 = json.load(open('data1.json'))
data2 = json.load(open('data2.json'))

for item in data1.keys():
    if data2[item] != data1[item]:
        print(f"{item} has differences")