Single quotes in JSON: “Expecting property name enclosed in double quotes”
Updated
JSON knows one quote character, and it isn’t this one. Keys and strings in JSON are wrapped in straight double quotes, ", and nothing else: {'name': 'Owl'} is a Python dict or a JavaScript literal, not JSON.
The error and the fix
Most of the time this text is the output of Python’s print() or str() on a dict, pasted where JSON was expected:
{'name': 'Owl', 'ready': True, 'backup': None}Swapping the quotes is not enough here: True and None are Python words too, and JSON spells them true and null (invalid literal). The real JSON for the same data:
{"name": "Owl", "ready": true, "backup": null}Why JSON accepts only double quotes
RFC 8259, section 7: “A string begins and ends with quotation marks.” The grammar names exactly one character for it, quotation-mark = %x22, the straight double quote. Object keys are strings by the same rule (“A name is a string”), so they need the same quotes.
JavaScript lets you pick between ' and "; JSON took a single choice, so a parser never has to guess where a string ends and an apostrophe inside a string is just a character. Formats built on top of JSON, such as JSON5, bring single quotes back; plain JSON never did.
Single quote error messages by parser
A single quote in place of a key, {'a': 1}, and in place of a value, {"a": 'b'}. Note how many parsers never mention quotes at all: they only say a key or a value was expected.
| Parser | Key: {'a': 1} | Value: {"a": 'b'} |
|---|---|---|
| Chrome, Edge, Node.js (V8) | Expected property name or '}' in JSON at position 1 (line 1 column 2) | Unexpected token ''', "{"a": 'b'}" is not valid JSON |
| Node.js 18, older Chrome (V8 10.2) | Unexpected token ' in JSON at position 1 | Unexpected token ' in JSON at position 6 |
| Firefox | JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data | JSON.parse: unexpected character at line 1 column 7 of the JSON data |
| Safari | JSON Parse error: Single quotes (') are not allowed in JSON | JSON Parse error: Single quotes (') are not allowed in JSON |
| Python | Expecting property name enclosed in double quotes: line 1 column 2 (char 1) | Expecting value: line 1 column 7 (char 6) |
| Go (encoding/json) | invalid character '\'' looking for beginning of object key string | invalid character '\'' looking for beginning of value |
| Java (Jackson 2) | Unexpected character (''' (code 39)): was expecting double-quote to start field name | Unexpected character (''' (code 39)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false') |
| C# (System.Text.Json) | ''' is an invalid start of a property name. Expected a '"'. | ''' is an invalid start of a value. |
| C# (Newtonsoft.Json) | No error: single quotes are accepted | No error: single quotes are accepted |
| PHP (json_decode) | Syntax error, json_last_error() 4 | Syntax error, json_last_error() 4 |
| Rust (serde_json) | key must be a string at line 1 column 2 | expected value at line 1 column 7 |
| jq 1.8 | jq: parse error: Invalid string literal; expected ", but got ' at line 1, column 5 | jq: parse error: Invalid string literal; expected ", but got ' at line 1, column 10 |
Only Safari and jq 1.8 name the quote; jq 1.7 still reports Invalid numeric literal for the same input. Newtonsoft.Json reads single quotes without complaint, which is how such “JSON” survives in one service and breaks the next one. Checked by running: Node.js 18, 24 and 25.1, Safari 27, Python 3.9 and 3.14, Go 1.25–1.27, Jackson 2.22, System.Text.Json and Newtonsoft.Json 13.0.4, PHP 8.3 and 8.5, serde_json 1.0, jq 1.7 and 1.8; Firefox from its source code and Mozilla’s reference.
Where single quotes come from
- Python’s
print(),str(),repr()or an f-string of a dict. That is Python syntax: single quotes,True,False,None. Python’s ownjsonmodule rejects it. - JSON built by hand in code: a template string or a string concatenation where single quotes were easier to type than escaped double ones.
- Shell commands.
curl -d "{'name': 'Owl'}"avoids escaping inside double quotes and sends invalid JSON. - Lenient readers upstream. Newtonsoft.Json, Jackson with
JsonReadFeature.ALLOW_SINGLE_QUOTES, JSON5 and YAML parsers accept single quotes, so the problem appears only when a strict parser reads the same text.
How to fix single quotes in code
Replacing every ' with " is a trap: Python writes a string that contains an apostrophe in double quotes, so the replacement breaks exactly those values. Fix the code that produced the text and use the language’s JSON serializer.
Python
import ast
import json
data = {"name": "Owl", "ready": True, "backup": None}
print(str(data)) # {'name': 'Owl', 'ready': True, 'backup': None}
print(json.dumps(data)) # {"name": "Owl", "ready": true, "backup": null}
# Only have the printed dict from a log? It is a Python literal: read it as one.
text = "{'name': 'Owl', 'ready': True, 'backup': None}"
print(json.dumps(ast.literal_eval(text)))JavaScript
const user = { name: "Owl", ready: true };
// A template string is not a serializer: quotes and escapes are on you.
const handMade = `{'name': '${user.name}'}`;
console.log(handMade); // {'name': 'Owl'}, not JSON
console.log(JSON.stringify(user)); // {"name":"Owl","ready":true}Go
package main
import (
"encoding/json"
"fmt"
)
func main() {
m := map[string]any{"name": "Owl", "ready": true}
fmt.Printf("%v\n", m) // map[name:Owl ready:true], Go syntax
b, _ := json.Marshal(m)
fmt.Println(string(b)) // {"name":"Owl","ready":true}
}Java (Jackson)
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.LinkedHashMap;
import java.util.Map;
Map<String, Object> m = new LinkedHashMap<>();
m.put("name", "Owl");
m.put("ready", true);
System.out.println(m); // {name=Owl, ready=true}
System.out.println(new ObjectMapper().writeValueAsString(m)); // {"name":"Owl","ready":true}C#
using System.Text.Json;
var user = new { name = "Owl", ready = true };
Console.WriteLine(user); // { name = Owl, ready = True }
Console.WriteLine(JsonSerializer.Serialize(user)); // {"name":"Owl","ready":true}PHP
$user = ['name' => 'Owl', 'ready' => true];
var_export($user); // PHP syntax with single quotes
echo "\n", json_encode($user); // {"name":"Owl","ready":true}Shell (curl)
# Single quotes around the body for the shell, double quotes inside it for JSON.
curl -X POST https://example.com/api/users -H "Content-Type: application/json" -d '{"name": "Owl"}'How to keep single quotes out of JSON
- Never print a dict, map or object and call the result JSON: log
json.dumps(data), notdata. - Build request bodies with a serializer, even for one field.
- Read JSON with a strict parser in tests, so a lenient one in production doesn’t hide the problem.
- Paste suspicious text into the JSON validator: it names the problem
single_quotesinstead of a generic “unexpected character”.
Try it in the validator
Open a sample with single quotes in the JSON validator: it stops at the first ', reports single_quotes with its line and column, and suggests json.dumps() if the text came from Python.
Related: smart quotes, unquoted key, invalid literal (True, None, NaN), the Python message on its own: Expecting property name enclosed in double quotes, and all JSON errors.
Single quotes in JSON FAQ
Can JSON use single quotes?
No. Keys and strings take straight double quotes only. A single quote is allowed inside a double-quoted string as an ordinary character.
Why does Python say “Expecting property name enclosed in double quotes”?
It found something other than " where a key had to start. The usual causes: single quotes from str(dict), an unquoted key, a trailing comma before } or a comment.
How do I convert a Python dict string to JSON?
If you have the dict, call json.dumps(data). If you only have its printed text, parse it with ast.literal_eval and then call json.dumps; don’t replace quotes by hand.
Why does the same JSON work in C# and fail elsewhere?
Newtonsoft.Json accepts single quotes by default. System.Text.Json, browsers, Python and Go don’t, so the text only looks valid until a stricter reader gets it.