1、少量文件对比可以使用在线Json对比工具,比如:
JSON Diff - The semantic JSON compare tool
https://jsoncompare.com/
都是不错的在线Json对比工具;
2、如果是大量的json文件需要对比,直接用 Byond Compare对比,由于对比工具不支持json格式化,会比较难观察差异点;所以,首先需要对json文件做预处理,使用以下脚本,放在j和jison文件放在同一个文件夹下,执行脚本,预处理之后,再使用Byond Compare工具进行对比,就可以很方便的观察到差异点了。
# coding:utf8 import json import sys,os def getFileCon(filename): if not os.path.isfile(filename): return with open(filename, "r") as f: con = f.read() f.close() return con def writeFile(filepath,con): with open(filepath, "w") as f: f.write(con) f.close() if __name__ == "__main__": fl = os.listdir(".") for f in fl: g = f if not f.endswith(".json"): continue try: con = json.loads(getFileCon(f)) # print con # writeFile(f,json.dumps(con,indent=4,ensure_ascii=False).decode('utf8')) writeFile(f,json.dumps(con,indent=4,ensure_ascii=False)) print (g,'OK') except Exception as e: print (g,'is not json format')