Skip to main content

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

Paste the text you passed to json.loads and click Validate to see what the parser sees first

14
Loading editor…

What the error means

json.loads and json.load expect a value (an object, array, string, number, true, false or null) at the current position and found something else. "line 1 column 1 (char 0)" means that happened at the first character of the text, so the whole text is the problem, not a typo deep inside it. A larger position, such as "line 5 column 12 (char 80)", points at a place later in the document where a value was expected, for example after a comma or a colon.

The validator above runs a different parser, so its wording is different ("Unexpected token" for the HTML sample it opens with), but it stops at the same character.

The usual causes at char 0

Print the text before parsing it (print(repr(text))) and match what you see against these cases.

Empty string or empty response

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

Invalid

import requests, json
response = requests.get(url)   # 204 No Content, or an error with no body
data = response.json()

Fixed

response = requests.get(url)
response.raise_for_status()
data = response.json() if response.content else {}

An empty body is not JSON. Check the status code and that the body has content before parsing. The same happens when json.loads receives "" from an empty file or an unset variable.

An HTML page instead of JSON

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

Invalid

<!DOCTYPE html>
<html><body>404 Not Found</body></html>

Fixed

{"status": "ok"}

A wrong URL, an expired login or a rate limit usually returns an HTML error or sign-in page. Print response.status_code and response.text[:200] to see it, then fix the URL, headers or credentials.

File read twice

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

Invalid

with open(path) as f:
    print(f.read())
    data = json.load(f)   # the file pointer is at the end

Fixed

with open(path) as f:
    text = f.read()
data = json.loads(text)

f.read() moves the file pointer to the end, so json.load(f) then reads an empty string. Read once and parse that string, or call f.seek(0) first.

Python values rather than JSON

Error: Expecting value: line 1 column 2 (char 1)

Invalid

['a', 'b']        # also: None, True, False

Fixed

["a", "b"]        # null, true, false

str() or print() of a Python list or dict produces Python syntax. Single quotes, None, True and False are not JSON. Produce the text with json.dumps(value) instead.

Trailing comma in an array (Python before 3.13)

Error: Expecting value: line 1 column 4 (char 3) (Python 3.13: Illegal trailing comma before end of array)

Invalid

[1, 2,]

Fixed

[1, 2]

JSON allows no comma after the last item. Older Python versions report it as a missing value at the closing bracket; 3.13 names the trailing comma.

Python's json module raises this when the very first thing it reads is not a JSON value. In most cases the text is not JSON at all: it is empty, or it is an HTML page. The line, column and char numbers say where the parser gave up.

Frequently Asked Questions

What do line, column and char mean?

They are three ways of giving the same position: the line and column (counting from 1) and the character offset from the start of the text (counting from 0). char 0 is the very first character.

Why does response.json() raise it but response.text looks fine?

response.text can be any text, including an HTML page or an empty string, and looks "fine" when printed. response.json() requires JSON. Print response.status_code and the first part of response.text, and check that the Content-Type header is application/json.

How is this different from 'Expecting property name enclosed in double quotes'?

That error is raised inside an object, where a key was expected, usually because of single quotes or a trailing comma. 'Expecting value' is raised where a value was expected, which at char 0 means the text does not start with JSON at all.

How do I validate the text without running Python?

Paste it into the editor above and click Validate. It reports the line and column of the first problem without sending the text anywhere.

Have suggestions or feedback? We're constantly improving FormatChamp based on your comments.