JSON Errors / Python
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)How to Fix: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Python's json module could not find any JSON value at the very start of the input. The three usual suspects: the string is empty, it is actually HTML or plain text, or it starts with an invisible BOM character.
With the requests library this almost always means the API call did not return JSON - check response.status_code and response.text before calling response.json().
Common causes
1. Empty response body
A 204 No Content, a failed request, or an endpoint that returns nothing - json.loads("") raises exactly this error.
json.loads("") # Expecting value: line 1 column 1 (char 0)2. HTML or plain-text response
Error pages, rate-limit messages ("Too Many Requests"), and login redirects are not JSON. requests will happily hand them to you; .json() then fails at char 0.
3. UTF-8 BOM in a file
A file saved as "UTF-8 with BOM" starts with \ufeff, which json.load() rejects. The file looks perfectly valid in an editor.
with open("data.json", encoding="utf-8-sig") as f: # -sig strips the BOM
data = json.load(f)4. Wrong file mode or path
Reading a file that is empty (e.g. opened with "w" earlier in the script, which truncated it) or reading the wrong path that resolves to an empty file.
How to fix it
import requests
resp = requests.get(url, timeout=10)
resp.raise_for_status() # raises on 4xx/5xx instead of parsing an error page
if not resp.text.strip():
data = None # empty body - decide your fallback
else:
print(resp.headers.get("Content-Type"))
print(resp.text[:200]) # inspect what actually came back
data = resp.json()import json
with open("data.json", encoding="utf-8-sig") as f:
data = json.load(f)Frequently asked questions
Why does "Expecting value" also appear for positions beyond char 0?
The same error at a later position (e.g. "line 3 column 14") means the document started fine but a value is missing at that spot - a trailing comma before ] or }, or an unquoted value. At char 0 specifically, the whole input is empty or non-JSON.
requests.json() vs json.loads(response.text) - any difference?
resp.json() is essentially json.loads(resp.text) with encoding detection. Both raise JSONDecodeError on non-JSON input. The fix is the same either way: verify status code and content type before parsing.
How do I debug this in one line?
print(repr(resp.text[:100])) - repr() makes invisible characters visible, so you will see '' (empty), '<!DOCTYPE...' (HTML), or '\ufeff{...' (BOM) immediately.
Last updated:
Related JSON errors
You might also need
Free and in-browser, like everything on JSON Console. Browse all tools →