Noman
Noman

Reputation: 15

Compare json files

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.

Upvotes: -3

Views: 325

Answers (1)

Ashe Muller
Ashe Muller

Reputation: 33

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")

Upvotes: 0

Related Questions