JSON Errors / All languages

Unexpected token ''' - single quotes in JSON

How to Fix: Unexpected token ''' - single quotes in JSON

JSON strings must use double quotes - 'single quotes' are invalid for both keys and values, and every standards-compliant parser rejects them. The error wording varies by language ("Unexpected token '" in JavaScript, "Expecting property name" or "Expecting value" in Python) but the cause is the same.

Single-quoted data usually comes from Python str(dict) output, JavaScript source code, or hand-written configs by people used to those languages.

{"find": "error"}paste your JSON below

Common causes

1. Hand-written JSON with single quotes

Muscle memory from Python or JavaScript, where single quotes are idiomatic.

Invalid
{'name': 'Ada', 'tags': ['pioneer']}
Valid
{"name": "Ada", "tags": ["pioneer"]}

2. Python dict output pasted as JSON

print(my_dict) shows Python's repr format with single quotes. It is Python literal syntax, not JSON.

3. Shell quoting confusion

In curl commands, the outer single quotes belong to the shell - the JSON inside must still use double quotes: curl -d '{"key": "value"}'.

Invalid
curl -d '{'key': 'value'}'   # broken shell quoting AND broken JSON
Valid
curl -d '{"key": "value"}'   # single quotes for shell, double for JSON

How to fix it

Convert Python-style data safely (Python)
import ast, json

python_style = "{'name': 'Ada', 'age': 36}"
data = ast.literal_eval(python_style)  # parses Python literals, not code
valid_json = json.dumps(data)          # '{"name": "Ada", "age": 36}'
Never fix with find-and-replace
// Replacing ' with " corrupts strings containing apostrophes:
{'note': "it's broken"}  →  {"note": "it"s broken"}   // now invalid differently
// Parse with a tolerant parser (JSON5) or the source language, then re-serialize.

Frequently asked questions

Why does JavaScript accept single quotes but JSON does not?

JavaScript string literals allow both quote styles as a language convenience. JSON was specified as a minimal, strict interchange format - one quote style means simpler, faster, more interoperable parsers. JSON.parse() enforces the spec even though JS itself is permissive.

My API client sends single-quoted JSON. What happens?

Any compliant server rejects it, typically with a 400 Bad Request. Fix the producer: use the language's JSON serializer (json.dumps, JSON.stringify) instead of string formatting or repr output.

Are there parsers that accept single quotes?

JSON5 and some lenient parsers (like Python's demjson or hjson) accept them, and this can help when rescuing legacy data. For anything that talks to standard tooling or APIs, produce strict JSON.

Last updated:

Related JSON errors

You might also need

Free and in-browser, like everything on JSON Console. Browse all tools →