Encounter: Json.decoder.jsondecodeerror: Expecting Value: Line 1 Column 1 (char 0)
I got the json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) when I tried to access to the values from a json file I created. I ran the runfile below, and it s
Solution 1:
The problem is this piece of code:
with open(new_path) as data_file:
data = data_file.read()
print(data)
data_content = json.load(data_file)
You are reading the contents of the file into data
, printing it, and then asking json.load()
to read from the filehandle again. However at that point, the file pointer is already at the end of the file, so there's no more data, hence the json error: Expecting value
Do this instead:
with open(new_path) as data_file:
data = data_file.read()
print(data)
data_content = json.loads(data)
You already have your data read into data
, so you can just feed that string into json.loads()
Post a Comment for "Encounter: Json.decoder.jsondecodeerror: Expecting Value: Line 1 Column 1 (char 0)"