简体   繁体   English

比较 json 个文件

[英]Compare json files

I have two json files.我有两个 json 文件。

File1.json File2.json文件 1.json 文件 2.json

Using python, I want to compare both files and write differences in third file Output.json使用 python,我想比较两个文件并在第三个文件 Output.json 中写入差异

Output file should be easy to read. Output 文件应该易于阅读。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM