Skip to content

/errors/json/expecting-value-line-1-column-1

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
JSON
exit code
1
versions
Python 3.5+
os
any

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) means the JSON parser found no JSON value at the very first character. The input is either empty or starts with something that is not JSON, most often an HTML page. The fix is to look at what you actually received (status code, headers, raw text) before calling json.loads() or response.json().

Reproduce it

bash
cat > parse.py <<'EOF'
import json
for raw in ["", "<!DOCTYPE html><html>502 Bad Gateway</html>", "\ufeff{}", "{'a': 1}", '{"a": 1'] :
    try:
        json.loads(raw)
        print("ok      ", repr(raw))
    except json.JSONDecodeError as e:
        print(f"{type(e).__name__}: {e}   <- {raw[:20]!r}")
EOF
python parse.py

Output

JSONDecodeError: Expecting value: line 1 column 1 (char 0)   <- ''
JSONDecodeError: Expecting value: line 1 column 1 (char 0)   <- '<!DOCTYPE html><html'
JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)   <- '\ufeff{}'
JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)   <- "{'a': 1}"
JSONDecodeError: Expecting ',' delimiter: line 1 column 8 (char 7)   <- '{"a": 1'

Only the first two inputs give Expecting value: line 1 column 1 (char 0); the others fail with their own messages, which point at the actual problem (a BOM, single quotes, truncated input).

Debug a failing API call

python
resp = requests.get(url, timeout=10)
print(resp.status_code, resp.headers.get("Content-Type"))
print(resp.text[:200])            # look at the start of the body
resp.raise_for_status()           # stop on 4xx/5xx before parsing
data = resp.json() if resp.content else None

requests raises requests.exceptions.JSONDecodeError with the same message, and it is a subclass of the standard json.JSONDecodeError, so except json.JSONDecodeError catches both.

MessageUsual cause
Expecting value: line 1 column 1 (char 0)Empty body or HTML instead of JSON
Unexpected UTF-8 BOM (decode using utf-8-sig)File or response starts with a BOM
Expecting property name enclosed in double quotesSingle quotes or a trailing comma (Python dict syntax, not JSON)
Expecting ',' delimiterTruncated or concatenated JSON
Extra dataTwo JSON documents in one string (JSON Lines needs one loads() per line)

Sources