def write_json_diff_to_file(self, json_object1, json_object2, output_file):
"""
Compares two json objects and if they does not match writes the
difference into the output file
"""
result = self.compare_json_objects(json_object1, json_object2,
write_diff_to_console=False)
status = True
if not result:
status = False
sorted_json1 = self.sort_json_object(json_object1)
sorted_json2 = self.sort_json_object(json_object2)
json_obj1 = json.dumps(
sorted_json1, indent=4, separators=(',', ':'),
encoding="utf-8")
json_obj2 = json.dumps(
sorted_json2, indent=4, separators=(',', ':'),
encoding="utf-8")
te = open(output_file, 'w')
diff = ("\n".join(
difflib.ndiff(json_obj1.splitlines(), json_obj2.splitlines())))
te.write(diff)
te.close()
return status
json_utils_class.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录