The Json.Load, JSONDecodeError: Expecting Value: Line 1 Column 1 (Char 0)

1.4K    Asked by ananyaPawar in Python , Asked on Nov 18, 2022
 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)
Answered by Amit raj

To resolve the jsondecodeerror: expecting value: line 1 column 1 (char 0) -


json.loads() takes a JSON encoded string, not a filename. You want to use json.load() (no s) instead and pass in an open file object:
with open('/Users/JoshuaHawley/clean1.txt') as json file:
    data = json.load(jsonfile)

The open() command produces a file object that json.load() can then read from, to produce the decoded Python object for you. The with statement ensures that the file is closed again when done. The alternative is to read the data yourself and then pass it into json.loads().



Your Answer

Interviews

Parent Categories