Expecting value: line 1 column 1 (char 0)

ErrorPython

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.

broken.jsonFails to parse
{
  "name": "Ada",
  "active": None
}
JSON.parse stops at line 3, column 13.

Line 3: change None to null.

fixed.jsonParses
{
  "name": "Ada",
  "active": null
}
JSON.parse reads it.

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.

Console
  • 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

  1. The body was empty (this is what char 0 usually means)

    A 204 No Content, a HEAD request, a redirect that returned nothing, or a connection that dropped. response.json() ends up calling json.loads(""), and there is no value in an empty string. Print repr(response.text[:200]) and you will usually see the problem straight away.

  2. 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 cheerful 200 on every one of them. Call response.raise_for_status() before you parse and most turn into an error that names the real problem.

  3. Python literals in the document

    JSON spells them null, true and false. Python spells them None, True and False. Any document built with str(some_dict), or copied out of a repr, carries the Python spellings. That is what the example below shows.

  4. You passed a path instead of the contents

    json.loads("data.json") tries to parse the filename itself, all nine characters of it. Use json.load(f) with an open file, or json.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.

What you put into the tools never leaves your browser. We count page views and keep them for 90 days. Accept and we also remember this browser, so a return visit is not counted as new. Privacy policy