If you write JSON with single quotes and try to parse it, you'll see an error like SyntaxError: Unexpected token ' in JSON at position 0 or Expected property name or '}' in JSON at line 1. The fix is straightforward: JSON requires double quotes for every string and every object key, without exception.
The rule: double quotes everywhere
The JSON specification (RFC 8259) defines a string as a sequence of Unicode characters wrapped in double quotes. This applies to both values and object keys:
// Invalid JSON — single quotes
{
'name': 'Alice',
'age': 30
}
// Valid JSON — double quotes
{
"name": "Alice",
"age": 30
}
Why does this trip developers up?
JavaScript allows both single and double quotes in object literals, so it is natural to write:
// Valid JavaScript object literal (NOT JSON)
const user = { 'name': 'Alice', 'age': 30 };
This works fine in JavaScript code, but the moment you try to pass that string as JSON — via an API, a config file, or JSON.parse() — it will fail. JSON is a stricter, language-independent text format and it does not inherit JavaScript's flexibility.
Apostrophes inside strings
A related question: if you cannot use single quotes as delimiters, what do you do when a value contains an apostrophe?
// An apostrophe inside a double-quoted string is fine — no escaping needed
{
"note": "It's a beautiful day"
}
An apostrophe inside a double-quoted JSON string does not need to be escaped. Only double quotes inside a string value need a backslash escape:
{
"message": "She said \"hello\""
}
Converting from single to double quotes
If you have a large block of single-quoted JSON-like text from a script or log output, a simple approach in most editors is a find-and-replace, but be careful — a global replace of ' with " will also replace apostrophes inside values. A more reliable approach:
- Paste the text into the JSON Validator — it will report the exact positions that fail.
- Fix the delimiters on keys and string values, leaving apostrophes inside values untouched.
- Validate again to confirm the document is now valid.
JSON vs JavaScript object literals
To summarize the key differences between JSON and a JavaScript object literal:
- JSON keys must be strings in double quotes. JS keys can be unquoted identifiers or single/double-quoted strings.
- JSON does not allow trailing commas. JS does (in modern engines).
- JSON does not allow comments. JS does (with
//and/* */). - JSON does not allow
undefined,NaN, orInfinity. JS objects can hold these values.
When you need to serialize a JavaScript object to JSON, always use JSON.stringify() — it produces valid JSON with double-quoted keys and values automatically.