Single quotes are not valid in JSON — use double quotes

The JSON standard only has one string delimiter: the straight double quote ". Single quotes, backticks and typographic “curly” quotes are all rejected, both around keys and around values. An apostrophe inside a double-quoted string is fine and needs no escaping.

Seen as:

  • SyntaxError: Expected property name or '}' in JSON at position 4 (line 2 column 3)
  • SyntaxError: Unexpected token ' in JSON at position 4
  • SyntaxError: JSON Parse error: Single quotes (') are not allowed in JSON
  • SyntaxError: JSON.parse: expected property name or '}' at line 2 column 3 of the JSON data
  • json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 3 (char 4)

Input

Settings

History

Load from URL

Common causes

1. A Python dict printed instead of serialized

print(data) and str(data) produce Python syntax: single quotes, True, None. Use json.dumps to write JSON.

Before
print(order)
After
print(json.dumps(order, indent=2))

2. Shell quoting in a curl command

Wrapping the body in double quotes for the shell tempts you to use single quotes inside it. Put the JSON in single quotes for the shell and keep double quotes inside.

Before
curl -X POST https://api.example.com/users -d "{'name': 'Ada'}"
After
curl -X POST https://api.example.com/users -H 'Content-Type: application/json' -d '{"name": "Ada"}'

3. An escaped apostrophe

\' is a JavaScript escape, not a JSON one. Inside a double-quoted JSON string the apostrophe needs no escape at all; \' is rejected as an invalid escape.

Before
{"quote": "It\'s done"}
After
{"quote": "It's done"}

4. Curly quotes from Word, Slack or a CMS

Rich-text editors replace straight quotes with “ ” and ‘ ’. They look similar but are different characters. Paste JSON through a plain-text editor or turn off smart quotes.

Before
{“name”: “Ada Lovelace”}
After
{"name": "Ada Lovelace"}

Frequently asked questions

Why does JSON not allow single quotes?

JSON’s grammar was kept deliberately small so every language could parse it the same way, and it defines strings with double quotes only. JSON5 allows single quotes if you control both ends.

How do I put a double quote inside a JSON string?

Escape it with a backslash: “She said "hi"”. A serializer such as JSON.stringify or json.dumps does this for you.

Can I convert single quotes automatically?

Yes. Fix it in PasteKit swaps single-quoted keys and strings to double quotes and escapes any double quotes inside them. Check the diff, because an apostrophe inside a single-quoted string can be ambiguous.

Related