Fix Single Quotes in JSON
JSON strings and object keys must use double quotes. Single-quoted values are common in JavaScript snippets, Python-like output, and LLM responses.
Why Single Quotes Fail
Strict RFC 8259 JSON only accepts double-quoted strings. A parser will reject {'name':'Ada'} even though JavaScript developers may recognize the shape.
Broken Example
{
'name': 'Ada',
'active': true
}
Fixed JSON
{
"name": "Ada",
"active": true
}
Same data, single quotes swapped for double quotes around both keys and string values.
How Different Languages Report It
The error message varies by parser, but the root cause and the fix are identical:
| Language / parser | Error message |
|---|---|
JavaScript (JSON.parse, V8) |
SyntaxError: Expected property name or '}' in JSON at position 1 (Node 22+) / Unexpected token ' (older runtimes) |
Python (json.loads) |
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1) |
Go (encoding/json) |
invalid character '\'' looking for beginning of object key string |
| jq | parse error: Expected string at line 1, column 2 |
Single-quoted JSON is part of the broader Unexpected token family — the ' row in that table routes back here.
Where Single-Quoted Text Comes From
Python's repr() and dict printing, JavaScript object literals copied from console output, Ruby hash inspection, and many LLM responses all use single quotes. None of these are JSON — they are language-native literals that happen to look similar. The fix is always the same direction (single → double); the question is just how to do it safely.
Why Find-and-Replace Is Risky
A blind replace of ' with " breaks any value that contains an apostrophe:
// ❌ Naive replace — turns one error into a different one
"{ 'note': 'it\\'s fine' }".replace(/'/g, '"')
// → { "note": "it\"s fine" } ← the " inside the value now ends the string
After replacement, the escaped single quote inside the value becomes an unescaped double quote, which collides with the new string delimiter. A safe converter has to track string-context boundaries and only swap the delimiters, not interior characters.
The Safe Conversion Strategy
Tokenize the input first: walk the text, identify string boundaries by their opening quote, and rebuild each token with double quotes — escaping any interior double quotes and unescaping the now-redundant escaped single quotes. Paste the payload into JSON Fix to do this in one pass, in your browser; then run the result through the strict JSON validator to confirm nothing else is wrong.
Related JSON Syntax Errors
Single-quoted JSON often arrives with other JavaScript-style sins in the same payload: unquoted keys, trailing commas, line comments, or undefined values. After fixing quotes, validate the result to surface anything still left. The repair workflow hub walks through the full sequence.
FAQ
Are single-quoted strings valid in JSON5?
Yes — JSON5 allows them. JSON5 is a human-edit-friendly superset (used by some build tools and config formats) but is not RFC 8259 JSON; don't use it for wire protocols, API payloads, or anything crossing a language boundary.
Will Python's json.loads accept single quotes?
No. If the source really is a Python literal (the output of print(some_dict), for example), use ast.literal_eval instead of json.loads — it parses Python syntax, including single quotes and tuples. If the source is meant to be JSON, convert the quotes first using the safe-conversion strategy above.
Do JSON keys need double quotes too?
Yes — keys are strings, same rule. { "name": "Ada" } is valid; { name: "Ada" } and { 'name': "Ada" } are both rejected.
For the deeper explainer on why JSON requires double quotes — and how this differs from a JavaScript object literal — see JSON vs JavaScript object: why single quotes aren't allowed.
See also
This guide is one stop in a larger repair workflow that covers trailing commas, unquoted keys, single quotes, and stringified-object errors. Open the hub for the full sequence.
Sources
- RFC 8259 — the JSON Data Interchange Format (IETF, the canonical JSON grammar)
- ECMA-404 — the JSON Data Interchange Syntax
- MDN —
JSON.parse(the strict parser that emits this error in JavaScript) - JSON5 — the human-edit-friendly superset that does allow single quotes
Last reviewed June 2026.
JSON repair guides
Topic hubs
- JSON Parse Errors: Read the Message, Jump to the Fix
- Fix Invalid JSON: From 'What's Wrong' to a Clean File
- JSON Formatter, Validator, Viewer: Pick the Right Tool
- Repair LLM JSON Output: Handling Almost-JSON from AI
- Privacy: JSON Tools That Don't Leave Your Browser
- JSON Interop: YAML, CSV, XML, JWT, Schema
Specific guides
- How to Decode Base64 Strings (and JWT Payloads)
- URL Encoding: Percent-Encode Query Parameters and Paths
- Convert YAML to JSON (and Avoid Indentation Errors)
- Convert JSON to CSV: Flatten an Array of Objects
- Convert JSON to XML: Root Elements, Attributes, and Arrays
- Escape JSON as a String Literal (and Decode Double-Encoded JSON)
- Fix Trailing Comma in JSON
- Fix Unquoted Keys in JSON
- Repair LLM JSON Output
- Fix JSON Parse Error: Expected Property Name
- JSON vs JS Object Literal: The Key Differences
- Validate JSON Before API Requests
- JSON Formatter vs JSON Repair
- Fix JSON Unexpected Token Errors
- JSON to JavaScript Object Converter