How browsers word it
| Chrome and Node (V8), newer | Expected property name or '}' in JSON at position 1 (line 1 column 2) |
|---|---|
| Chrome and Node, older | Unexpected token ' in JSON at position 1 |
| Firefox | JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data |
| Safari | JSON Parse error: Expected '}' |
Common causes
A printed Python dictionary
print(my_dict) writes single quotes, and True and None instead of true and null. That is Python syntax, not JSON.
Input
{'ok': True}JSON Formatter says
Single quotes are not valid JSON. Use double quotes around keys
A JavaScript object literal
Code often uses single quotes for strings. They are fine in JavaScript, but JSON.parse only accepts double quotes.
Input
{"a": 'x'}JSON Formatter says
Single quotes are not valid JSON. Use double quotes
Keys without quotes
JavaScript allows {a: 1}. JSON does not: every key needs double quotes.
Input
{a: 1}JSON Formatter says
Expected a key in double quotes but found "a". Keys must be quoted
How to fix it
- In Python write JSON with json.dumps(value), not str(value) or print(value).
- In JavaScript write JSON with JSON.stringify(value), not a hand-typed string.
- To fix a short text by hand, replace every single quote with a double quote, and True, False and None with true, false and null.
- Paste the text into the JSON formatter to find any other problem.