Single quotes in JSON

ErrorJavaScript

SyntaxError: Expected property name or '}' in JSON at position 4 (line 2 column 3)

Where it stops

{
  'name': 'Ada',
  'active': true

What 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.

broken.jsonFails to parse
{
  'name': 'Ada',
  'active': true
}
JSON.parse stops at line 2, column 3.

Lines 2 and 3 change.

fixed.jsonParses
{
  "name": "Ada",
  "active": true
}
JSON.parse reads it.

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.

Console
  • 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

  1. 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/None instead of true/false/null.

  2. 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.

  3. Shell quoting

    Wrapping a JSON payload in single quotes for curl is 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.

What you put into the tools never leaves your browser. We count page views and keep them for 90 days. Accept and we also remember this browser, so a return visit is not counted as new. Privacy policy