-3

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.

Noman
  • 15
  • 6

1 Answers1

0

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")
  • Hi, Above code is working fine on simple json format but my json file is one below format: { "list": [{ "id": "97c7d810-f101-11eb-ae60-39ee5de7b677", "original_statement": { "id": "2403002a-17a5-4cfc-b87b-7de693328362", "meta": { "createdAt": "2021-07-30T06:44:30.000Z" }, "tags": [{ "key": "entityType", "value": "medicalCondition" }, { "key": "context", "value": "oblemsAsthmaMalignant neoplasm of sigmoid colon ﴾Noted 7/11/2016﴿Thyroid nodule" } ] } }] } your code result is list has differences. – Noman Sep 24 '21 at 17:19