Expecting property name enclosed in double quotes (Python Fix)
Python raises this when json.loads() finds a key that is not in double quotes, or a trailing comma before a closing brace. Here are the causes and fixes.
Have broken JSON right now? Fix it free in under 1 second — no signup.
Fix My JSON →Python's json module raises this error when it expects an object key and finds anything other than a double-quoted string. The usual culprits are single-quoted keys, unquoted keys, and a trailing comma before the closing brace.
What “JSONDecodeError: Expecting property name enclosed in double quotes” means
The parser wanted a key and did not get one in double quotes. In JSON, every object key is a string, and a string starts with a double quote. After a comma inside an object, Python's decoder expects another key. If it sees a single quote, a bare word, or a closing brace, it stops. The error message includes the line and column where it gave up, so start there.
Causes and the fix for each
Trailing comma after the last pair
A comma tells the parser another key follows. If the next character is a closing brace, the parser has no key to read and raises this error. JSON does not allow trailing commas. Many editors and Python itself accept them, which is why they slip in.
Before (fails):{"id": 1, "ok": true,}
After (valid):
{"id": 1, "ok": true}
Unquoted keys copied from JavaScript
JavaScript object literals allow bare keys such as name: 1. JSON does not. Every key must be a string in double quotes. Config snippets, console output, and documentation examples often use the JavaScript form, so pasting them into json.loads() fails at the first key.
Before (fails):{name: "Ada", age: 36}
After (valid):
{"name": "Ada", "age": 36}
Single-quoted keys
JSON strings use double quotes only. Single quotes are valid in Python and JavaScript, but the JSON grammar does not define them. The decoder fails on the first quote character because it is not a double quote.
Before (fails):{'name': 'Ada'}
After (valid):
{"name": "Ada"}
A Python dict printed with str() or repr()
Printing a dict gives Python syntax, not JSON. Keys use single quotes, and values like True and None appear. Logging a dict and parsing the log line later is a common way to hit this error. Use json.dumps() to write JSON.
Before (fails):{'active': True, 'tag': None}
After (valid):
{"active": true, "tag": null}
A comment or stray text inside the object
JSON has no comment syntax. A line starting with // or # where a key should be gives the parser something that is not a double-quoted string. The same happens with leftover template placeholders or markdown text.
Before (fails):{
// user
"name": "Ada"
}
After (valid):
{
"name": "Ada"
}
How to fix it in Python
- Read the line and column in the error. The position points at the character where a key should start, often the closing brace after a trailing comma.
- Look at that spot. Check for a comma right before a closing brace, a single quote, or a bare word.
- If the text came from a Python dict, stop using str() or repr() and write it with json.dumps(data). That produces double quotes, true, false, and null.
- If the text came from JavaScript or a config file, remove comments and trailing commas, and wrap each key in double quotes.
- For larger or messy input, paste it into the Repair tool. It fixes quotes and trailing commas and shows the cleaned result.
- Run the result through the Validator to confirm it parses, then use the Formatter if you want it readable.
import json
import ast
def load_json(text):
try:
return json.loads(text)
except json.JSONDecodeError as e:
if "property name" not in e.msg:
raise
print(f"Bad key at line {e.lineno}, column {e.colno}")
start = max(e.pos - 20, 0)
print("Near:", repr(text[start:e.pos + 20]))
# The text may be a Python dict repr, not JSON.
try:
data = ast.literal_eval(text)
except (ValueError, SyntaxError):
raise e
# Round-trip through json.dumps so the result is JSON-safe.
return json.loads(json.dumps(data))
Variants of the message
| Message | Cause | Fix |
|---|---|---|
| Expecting property name enclosed in double quotes: line 1 column 2 (char 1) | First key is single-quoted or unquoted | Wrap the key in double quotes |
| Expecting property name enclosed in double quotes: line 3 column 1 (char 24) | Trailing comma before the closing brace | Remove the last comma |
| Expecting value: line 1 column 1 (char 0) | Empty string, HTML, or non-JSON text | Check the input and the response body |
| Expecting ',' delimiter: line 1 column 12 (char 11) | Missing comma between pairs or items | Add the comma |
| Expecting ':' delimiter: line 1 column 8 (char 7) | Key not followed by a colon | Add the colon after the key |
Related errors
- Single quotes are not valid JSON: Fixing json.loads() in Python
- JSONDecodeError: Expecting ',' delimiter: How to Fix It in Python
- Fix Python JSON Errors: json.loads() Decode Errors and How to Repair Them
- Invalid JSON Meaning: What It Is and How to Fix It
- JavaScript JSON.parse() Errors: What They Mean and How to Fix Them
Key takeaways
- The parser wanted a double-quoted key and found something else.
- Trailing commas, single quotes, and bare keys cause most cases.
- Use json.dumps() to write JSON. Do not use str() on a dict.
- The error shows line and column. Start there.
- Paste messy input into the Repair tool to clean it quickly.
FAQ
Why does json.loads() fail on a trailing comma when Python accepts one in a dict?
Python's own syntax allows trailing commas in dict literals. The JSON grammar does not, and json.loads() follows the JSON grammar. Remove the final comma.
Can I parse single-quoted keys with json.loads()?
No. The standard json module only accepts double-quoted strings. If the text is a Python dict repr, ast.literal_eval() can read it, but only use it on text you trust. Better to fix the source.
How do I find the exact spot of the error?
Catch json.JSONDecodeError and read its lineno, colno, and pos attributes. Print a slice of the text around pos to see the offending characters.
Why does the error say line 1 column 2 for my whole file?
The file is probably on one line, or the first key is the problem. Column 2 means the character right after the opening brace is not a double quote.
Still dealing with broken JSON?
Paste it in and get it fixed in under 1 second — free, no signup, no install. Works with ChatGPT, Claude, n8n, and any AI output.
Fix My JSON Free →Related Articles