Single quotes in JSON

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.

How the message appears

The same fault, worded by different engines. V8 (Chrome, Node, Edge) changed its format around Chrome 109, so older and newer runtimes disagree about the same document.

  • SyntaxError: Unexpected token ''', "{'name': "... is not valid JSON
  • SyntaxError: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data

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

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.

Fails to parse
{
  'name': 'Ada',
  'active': true
}
Parses
{
  "name": "Ada",
  "active": true
}

The example travels in the URL fragment, which browsers never send to a server.

Worth knowing

  • A double quote *inside* a string value must be escaped as \" once you switch. This is why a blind find-and-replace is risky and parsing is not.
  • Python users: json.dumps(obj) emits valid JSON; str(dict) and print(dict) do not.

No cookies, no accounts, no tracking. Your JSON and text are processed entirely in your browser and never sent anywhere. We count anonymous page views (the page address only, nothing about you or your device), and use localStorage to remember your theme.