Expecting property name enclosed in double quotes
Updated by John Marshall
JSON is strict about keys: every property name has to be in double quotes. Python raises this error when it finds one that isn’t, and JavaScript says Expected property name or '}' for the same thing. Usually the text is a Python dictionary or a JavaScript object that was printed instead of encoded as JSON.
Quick fix
- Look at the reported position. You’ll usually find a single quote, a curly quote, a name with no quotes, or a
}right after a comma. - If your own code produced the text, write it with
json.dumps()orJSON.stringify()instead. - To fix the copy you have, paste it below and choose Fix it.
Fix your JSON
What the parser tripped over
The error appears wherever the parser expects a key. One of these is usually sitting there instead:
- Single quotes, as in
{'name': 'Maya'}. That’s exactly how Python prints a dictionary, which is a strong hint about where the text came from. - No quotes at all, as in
{name: "Maya"}. JavaScript code allows it, and the browser console displays objects this way, but JSON doesn’t. - A trailing comma, as in
{"a": 1,}. After a comma the parser expects another key, and finds}. - Curly quotes, as in
{“name”: “Maya”}. Word, Pages and Google Docs swap straight quotes for curly ones as you type, and so do Macs and iPhones with smart quotes turned on. The JSON looks right, but parsers only accept the straight"character, so it fails at the first key. Fix My JSON swaps them back and leaves apostrophes inside your values alone. To stop it happening, write JSON in a code editor rather than a document. On a Mac, the setting is “Use smart quotes and dashes” in the keyboard’s text input options, and in Word it’s the straight quotes option under AutoFormat As You Type. - A comment, such as
// a note. Some config formats, like VS Code’s settings files, allow comments, but standard JSON parsers don’t. JSONC to JSON removes them.
Fixing it in Python
The usual cause is turning a dictionary into text with str(), print(), or an f-string. Those write Python syntax, not JSON. json.dumps() writes the real thing:
import json
data = {"name": "Maya", "active": True}
str(data) # {'name': 'Maya', 'active': True} not JSON
json.dumps(data) # {"name": "Maya", "active": true} JSONSometimes you can’t change the code that sends you dictionary-style text. In that case, read it with ast.literal_eval(), which understands Python literals but won’t run code. Avoid eval() here, because it will run anything in the text.
import ast, json
data = ast.literal_eval("{'name': 'Maya', 'active': True}")
json.dumps(data) # '{"name": "Maya", "active": true}'Fixing it in JavaScript
If you’re building JSON with template strings, switch to JSON.stringify(value). It quotes every key for you, and escapes the values too. If you’re reading a config file that’s meant to have comments or unquoted keys, it isn’t JSON. Read it with a JSON5 parser instead of JSON.parse.
The same error elsewhere
| Python | json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1) |
|---|---|
| Chrome, Edge, Node.js 20+ | Expected property name or '}' in JSON at position 1 |
| Chrome, Node.js (trailing comma) | Expected double-quoted property name in JSON at position 8 |
| Chrome, Node.js 22 (curly quotes) | Expected property name or '}' in JSON at position 1 (line 1 column 2) |
| Firefox | JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data |
| Go | invalid character '\'' looking for beginning of object key string |
| Older Chrome, Node.js 18 | Unexpected token ' in JSON at position 1 |