pythonjsonpycharmfile-comparison

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.


Solution

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