简体   繁体   中英

Error reading big json file due to json.load

I have a problem reading big json file. JSONDecodeError: Extra data: line 1 column 884 (char 883). 在此处输入图像描述

The files test2.json is here: https://github.com/SilverYar/TransportDataMiner

The error is due to these lines of line code:

import nltk
from nltk.stem.snowball import RussianStemmer
from nltk.corpus import stopwords
import nltk, string, json

with open('C:\\Creme\\token\\test2.json') as fin:
    text = json.load(fin)

I don't understand how to fix it. Help me fix it.

The content of your json file does not seem to be valid, there are multiple objects but not separated by ",".

For example, a valid json object should be:

[{"title":"some text", "subtitle": "some text"},
 {"title":"some text", "subtitle": "some text"},
{"title":"some text", "subtitle": "some text"}]

A simple hack to read it will be to read in the file and format the string into correct json formats:

with open('test2.json', 'r') as fin:
    text = fin.read()
    formated_text = text.replace('}{', '},{')
    json_data = json.loads(f'[{formated_text}]')

print(len(json_data))
# 11772

Well I understand the unveriatlifdoafoh GH (PO opg )))_FI++ SE(G&B in a sense with change, solve old (architecture, e2e testing, dev tools, etc.) and new (accessibility, Typescript integration, AI-chatbot adoption, etc.) problems are to get insights from different applied approaches throughout JS conferences. strong text

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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