比较jsons的两个文件以及由此产生的json差异 [英] Comparing two files of jsons and resulting json difference

查看:143
本文介绍了比较jsons的两个文件以及由此产生的json差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试比较两个文件,并且每一行都是JSON格式。我需要比较两个文件之间的每一行,并且应该返回差值。由于文件太大,我无法读取和比较每一行。请为我提供一些优化的方法。

I am trying to compare two files and each line is in JSON format. I need to compare each line between two files and should return the difference.Since the file size is too big and I am unable to read and compare each line.Please suggest me some optimised way in doing this.

推荐答案

两种可能的方法:


  1. 使用Josh发表的评论中提到的技术

  2. 使用此处提到的技术:
    如何在python中比较2个json

  1. Using the technique mentioned in the comment posted by Josh.
  2. Using the technique mentioned here : how to compare 2 json in python.

鉴于您的文件很大,最好使用difflib技术在第1点中进行了描述。

Given that you have a large file, you are better off using difflib technique described in point 1.

根据对以下答案的回答进行编辑

经过一番研究,发现处理大型数据有效负载的最佳方法是以流方式处理此有效负载。这样一来,我们就可以确保快速处理数据,同时牢记软件的内存使用情况和性能。

After some research, it appears that the best way to deal with large data payloads is to process this payload in a streamed manner. This way we ensure a speedy processing of the data keeping in mind the memory usage and performance of the software in general.

请参阅链接,该链接讨论了使用Python流JSON数据对象的问题。同样,请查看 ijson -这是python中基于迭代器的JSON解析/处理库。

Refer to this link that talks about Streaming JSON data objects using Python. Similarly take a look at ijson - this is an iterator based JSON parsing/processing library in python.

希望这可以帮助您确定一个合适的库,以解决您的用例

Hopefully, this helps you towards identifying a good fit library that will solve your use case

这篇关于比较jsons的两个文件以及由此产生的json差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆