简体   繁体   English

Python json解析非常大的文件

[英]Python json parsing very large files

I need to loop through a 30meg json file which is a large file for just text. 我需要遍历一个30meg的json文件,这是一个仅用于文本的大文件。 when simply using. 简单使用时。 Also I am using a feed from walmart https://developer.walmartlabs.com/docs/read/Special_Feeds . 我也使用来自沃尔玛的提要https://developer.walmartlabs.com/docs/read/Special_Feeds I am not sure if anyone is familiar with this. 我不确定是否有人熟悉这一点。

data = json.loads(open('file.json').read()) print data

I get this error ` 我得到这个错误

Traceback (most recent call last):
  File "/home/python/Desktop/read.py", line 21, in <module>
    data = json.loads(open('rolback.json').read())
  File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

` `

I think it is because the file is so large. 我认为是因为文件太大。 I have also tried to stream the file and get a memory error. 我也尝试过流文件并得到内存错误。

What options/what is recommended to deal with these very large files? 处理这些非常大的文件有什么选择/建议什么? Here is a link to a previouse questions that contains some of the output of the file. 这是指向先前问题的链接,其中包含文件的某些输出。 python ijson large file loop to get names python ijson大文件循环获取名称

The No JSON object could be decoded error means your json data contains invalid JSON data. No JSON object could be decoded错误意味着您的json数据包含无效的JSON数据。 30MB is pretty small and shouldn't be your issue. 30MB很小,不应该成为您的问题。

You can use simplejson to get a better error message in order to see exactly where your json contains an error. 您可以使用simplejson获得更好的错误消息,以准确查看json包含错误的位置。

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

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