What the Error Means
json.loads() and json.load() raise json.JSONDecodeError when the text is not valid JSON. The message says what the parser expected and where it stopped:
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
"Expecting value" means the parser wanted a JSON value (an object, array, string, number, true, false or null) and found something else. line 1 column 1 (char 0) means it failed on the very first character, so the problem is not a small typo: the text is empty or is not JSON at all.
Cause 1: The Text Is Empty
An empty string, an empty file or a body with only spaces all give this error. We tested json.loads("") and reading an empty .json file on Python 3.14: both raised Expecting value: line 1 column 1 (char 0). A body of only whitespace reports the position after the spaces, for example line 2 column 1 (char 4).
This happens when an API returns 204 No Content, when a request fails without a body, or when a file was created but never written. Check before parsing:
if not text.strip():
print("Nothing to parse: the response or file is empty")
else:
data = json.loads(text)Cause 2: The Response Is HTML, Not JSON
When an API call fails, many servers send an HTML error or login page. The first character is <, which is not a JSON value, so parsing <!DOCTYPE html>... raises the same Expecting value: line 1 column 1 (char 0). Look at what really came back:
import requests
response = requests.get("https://api.example.com/users/1", timeout=10)
print(response.status_code) # 404? 401? 500?
print(response.headers.get("Content-Type")) # text/html instead of application/json?
print(response.text[:200]) # the start of the real body
response.raise_for_status()
data = response.json()Common reasons: a wrong URL (404 page), a missing or expired API key (login page), a server error (500 page), or a proxy or firewall answering instead of the API. Fix the request, not the JSON parsing.
Cause 3: It Is a Python Dictionary, Not JSON
Printing a dict with print() or str() gives Python syntax, not JSON: single quotes and True, False, None. These are the errors Python 3.14 gave us:
| Text | Error |
|---|---|
{'name': 'Emily'} | Expecting property name enclosed in double quotes: line 1 column 2 (char 1) |
{"active": True} | Expecting value: line 1 column 12 (char 11), pointing at the T |
The real fix is to create the text with json.dumps() in the first place. If you only have the Python-style text, ast.literal_eval reads it safely:
import ast, json
text = "{'name': 'Emily', 'active': True, 'manager': None}"
data = ast.literal_eval(text) # a real dict
print(json.dumps(data))
# {"name": "Emily", "active": true, "manager": null}Or paste the text into JSON Repair, which converts single quotes, True, False and None for you.
Cause 4: A BOM at the Start of the File
Files saved by Excel or some Windows editors can start with an invisible byte order mark. Python names it in the error:
JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)
with open("data.json", encoding="utf-8-sig") as f:
data = json.load(f)Every JSONDecodeError Message and Its Fix
All messages below are from Python 3.14 with the text shown.
| Message | Example text | Cause and fix |
|---|---|---|
Expecting value | "", <!DOCTYPE html>, True | Empty text, HTML, or a Python value. See the causes above. |
Expecting property name enclosed in double quotes | {'name': 'Emily'} | Single quotes or a key without quotes. Use double quotes. |
Illegal trailing comma before end of object | {"name": "Emily",} | A comma after the last item. Remove it. Older Python versions report this as Expecting property name enclosed in double quotes. |
Expecting ',' delimiter | {"a": 1 "b": 2} | A missing comma between items. |
Extra data | two objects on two lines | More than one JSON value, often a JSON Lines file. Parse each line with json.loads. |
Unterminated string starting at | {"name": "Emily} | A missing closing quote. |
Invalid control character at | a real line break inside a string | Write it as \n, or pass strict=False to accept it. |
Not a JSONDecodeError but just as common: TypeError: the JSON object must be str, bytes or bytearray, not TextIOWrapper means you passed a file to json.loads. Use json.load(f) for files and json.loads(text) for strings. The same message ending in NoneType means the variable you parsed is None.
Find the Exact Spot
The exception has lineno, colno and pos attributes. Show the text around pos to see the mistake at a glance:
import json
def parse_json(text):
if not text or not text.strip():
raise ValueError("Empty response: nothing to parse")
try:
return json.loads(text)
except json.JSONDecodeError as e:
snippet = text[max(0, e.pos - 20): e.pos + 20]
raise ValueError(
f"Invalid JSON at line {e.lineno}, column {e.colno}: {e.msg}. Near: {snippet!r}"
) from eValueError: Invalid JSON at line 1, column 9: Expecting ',' delimiter. Near: '{"a": 1 "b": 2}'JSONDecodeError is a subclass of ValueError, so except ValueErrorcatches it too. For a quick check without code, paste the text into the JSON Validator: it highlights the same line and column.
Frequently Asked Questions
What does JSONDecodeError: Expecting value: line 1 column 1 (char 0) mean?
Python failed on the very first character, so the text is empty or is not JSON at all. Usually an API returned an empty body or an HTML error page, or a file is empty.
How do I fix JSONDecodeError when using requests?
Print response.status_code and response.text[:200] to see what the server really sent. Call response.raise_for_status() before response.json(), and fix the URL, API key or request that caused the error page.
Why does json.loads fail on a Python dictionary string?
str() and print() write Python syntax with single quotes and True, False and None, which is not JSON. Create the text with json.dumps(), or read the Python-style text with ast.literal_eval().
Is JSONDecodeError a ValueError?
Yes. json.JSONDecodeError is a subclass of ValueError, so except ValueError also catches it. It has lineno, colno and pos attributes that show where parsing stopped.