Expecting value: line 1 column 1 (char 0)
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Where JSON.parse stops
"name": "Ada",
"active": None
}What it means
Python got to a spot where a value has to begin and found something that cannot begin one. Read the offset first. char 0 means the document was empty, or was never JSON at all. Any larger number means one bad value inside a document that is otherwise fine.
Last verified on Python 3.9, 3.11, 3.12, 3.13 and 3.14; requests 2.34.
It opens with the error marked. Nothing is uploaded. Find where the error is.
- Usually
- The body was empty (this is what char 0 usually means)It is an HTML page, not JSONPython literals in the documentYou passed a path instead of the contents
- Fix
- Swap the Python literals for JSON ones.
The fix
Swap the Python literals for JSON ones. None becomes null, True becomes true, False becomes false. And if the offset says char 0, stop reading the JSON. Go and look at what the server actually sent back.
{
"name": "Ada",
"active": None
}Line 3: change None to null.
{
"name": "Ada",
"active": null
}How the message appears
The char offset counts characters from the start of the document, which is the one to trust when the whole document is a single line.
- json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- json.decoder.JSONDecodeError: Expecting value: line 3 column 13 (char 31)
- requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
What causes it
The body was empty (this is what char 0 usually means)
A
204 No Content, aHEADrequest, a redirect that returned nothing, or a connection that dropped.response.json()ends up callingjson.loads(""), and there is no value in an empty string. Printrepr(response.text[:200])and you will usually see the problem straight away.It is an HTML page, not JSON
Position 0 is
<. A 404 page, a login redirect, a proxy error, a bot check. Plenty of setups return HTML with a cheerful200on every one of them. Callresponse.raise_for_status()before you parse and most turn into an error that names the real problem.Python literals in the document
JSON spells them
null,trueandfalse. Python spells themNone,TrueandFalse. Any document built withstr(some_dict), or copied out of arepr, carries the Python spellings. That is what the example below shows.You passed a path instead of the contents
json.loads("data.json")tries to parse the filename itself, all nine characters of it. Usejson.load(f)with an open file, orjson.loads(path.read_text()).
Worth knowing
Watch outNever build JSON with str(obj) or an f-string. json.dumps(obj) is the one thing that turns a Python object into valid JSON, and it is also what escapes the quotes for you.
Watch outPython is looser than JSON in one place that catches people out. json.loads accepts NaN, Infinity and -Infinity by default, and json.dumps will happily write them. Pass allow_nan=False when the document has to be read by anything else.
NoteThe exception carries the numbers. except json.JSONDecodeError as e: gives you e.lineno, e.colno, e.pos and e.doc, all far more useful in a log than the printed string.