Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I am reading in a json.bz2 file.

This is the code

with open(full_filename, 'r', encoding='utf-8', errors='ignore') as the_file:    

    data = json.load(the_file)

Error:

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I tried searching on google for solutions, but none of them are works.

1 Answer

0 votes
by (36.8k points)

You are trying to decode a compressed JSON directly. You need to uncompress it first. You can use bz2 package. For example:

import json

import bz2

# ...

data = json.loads(bz2.BZ2File(full_filename).read().decode())

Improve your knowledge in data science from scratch using Data Scientist

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...