Single quotes in JSON
SyntaxError: Expected property name or '}' in JSON at position 4 (line 2 column 3)
Where it stops
{
'name': 'Ada',
'active': trueWhat it means
JSON defines exactly one string delimiter: the double quote. Single quotes are not an alternative form, they are not valid anywhere, and that applies to property names as well as to values.
Last verified on Chromium 145, Firefox 146, WebKit 26 and Node 20.
It opens with the error marked. Nothing is uploaded. Find where the error is.
- Usually
- Pasting a JavaScript or Python literalSmart quotes from a document or chat clientShell quoting
- Fix
- Replace every single quote around a key or string value with a double quote.
The fix
Replace every single quote around a key or string value with a double quote. true, numbers and null are never quoted at all.
{
'name': 'Ada',
'active': true
}Lines 2 and 3 change.
{
"name": "Ada",
"active": true
}How the message appears
Chrome and Node first, then Firefox, then Safari. Older versions of Chrome and Node word it differently. Those lines are marked.
- SyntaxError: Expected property name or '}' in JSON at position 4 (line 2 column 3)Chrome and Node
- SyntaxError: JSON.parse: expected property name or '}' at line 2 column 3 of the JSON dataFirefox
- SyntaxError: JSON Parse error: Single quotes (') are not allowed in JSONSafari
- SyntaxError: Unexpected token ''', "{"a": 'x'}" is not valid JSON
- SyntaxError: JSON.parse: unexpected character at line 1 column 7 of the JSON data
- SyntaxError: Expected property name or '}' in JSON at position 4Older V8 wording
What causes it
Pasting a JavaScript or Python literal
Both languages treat
'and"as interchangeable, so a dict or object literal copied straight out of source is usually not valid JSON. Python adds two more traps in the same paste:True/False/Noneinstead oftrue/false/null.Smart quotes from a document or chat client
Word, Google Docs, Slack and Notion silently replace straight quotes with the typographic pair “ ”. They look almost identical in a proportional font and are not quotes as far as a parser is concerned.
Shell quoting
Wrapping a JSON payload in single quotes for
curlis correct; letting those quotes end up inside the payload is not. If the JSON itself contains single quotes after the shell is done with it, the quoting nested one level too deep.
Worth knowing
Watch outA double quote inside a string value has to be escaped as \" once you switch. This is why a blind find-and-replace is risky and parsing is not.
NotePython users: json.dumps(obj) emits valid JSON; str(dict) and print(dict) do not.