Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How open and read JSON file?

I have json file but this file have weight 186 mb. I try read via python .

import json
f = open('file.json','r')
r = json.loads(f.read())

ValueError: Extra data: line 88 column 2 -...

FILE

How to open it? Help me


1 Answers

Your JSON file isn't a JSON file, it's several JSON files mashed together.

The first instance of this occurs in the 1630070th character:

'шова"}]}]}{"response":[{"count'
           ^ here

That said, jq appears to be able to handle it, so the individual parts are fine.

You'll need to split the file at the boundaries of the individual JSON objects. Try catching the JSONDecodeError and use its .colno to slice the text into correct chunks.

like image 174
L3viathan Avatar answered Jan 23 '26 20:01

L3viathan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!