JSON Single Quotes: Why They Are Invalid and How to Fix Them

JSON strings and keys must use double quotes. {'name': 'Ada'} is rejected by every strict parser. Paste your text below to see exactly where it fails, then convert it safely. The converter reads each string instead of doing a find-and-replace, so apostrophes and embedded quotes survive.

Ctrl/Cmd+Enter: convert

Runs entirely in your browser. Nothing you paste is uploaded.

Why JSON only accepts double quotes

JSON came from JavaScript's object literal syntax, but it was cut down on purpose so that every language could parse it the same way. RFC 8259, the JSON standard, says a string "begins and ends with quotation marks", meaning the double quote character " (U+0022). Object keys are strings too, so they follow the same rule. No single-quote form exists, no unquoted form, and no parser option in the standard turns either on.

So this is invalid everywhere:

{'name': 'Ada', 'langs': ['en', 'fr']}

and this is the same data as valid JSON:

{"name": "Ada", "langs": ["en", "fr"]}

Mixing styles does not help either. {"name": 'Ada'} fails at the value instead of the key.

Apostrophes inside JSON strings

This trips people up in both directions. Inside a double-quoted JSON string, an apostrophe needs no escaping at all:

{"title": "It's a trap", "user": "O'Brien"}

Writing "It\'s" is an error. JSON allows only these escapes: \" \\ \/ \b \f \n \r \t and \uXXXX. \' is not one of them, so a strict parser stops with an "invalid escape" error. If you really need to avoid the literal character (inside an HTML attribute, for example), write it as '.

The character you do have to escape is the double quote: "She said \"hi\"".

Why a find-and-replace of ' with " breaks things

The tempting fix is text.replace(/'/g, '"') or sed "s/'/\"/g". It works on the simplest input and silently damages everything else:

InputAfter a naive replaceResult
{'msg': 'It\'s fine'}{"msg": "It\"s fine"}Parses, but the value is now It"s fine. The data is silently corrupted.
{'title': "It's here"} (Python repr){"title": "It"s here"}Broken: the string ends after It
{'quote': 'She said "hi"'}{"quote": "She said "hi""}Broken: the embedded quotes are not escaped
{'title': 'It's here'}{"title": "It"s here"}Broken. The input was already ambiguous.

The first row is the worst case, because nothing fails. A careful conversion has to read the text the way a parser does: find where each string really starts and ends, decode its escapes, then write it back out with double quotes, escaping any " inside. That is what the converter above does. For the last, ambiguous case (an unescaped apostrophe inside a single-quoted string), it treats a quote between two letters as an apostrophe, because It's and O'Brien are far more common than a string that ends in the middle of a word. The change list tells you when it did.

Error messages for single quotes in JSON

These are the messages you will see for input like {'a': 1}:

WhereError message
Chrome, Edge, Node.js (current V8)SyntaxError: Expected property name or '}' in JSON at position 1, and newer versions add (line 1 column 2). For a single-quoted value such as {"a": 'b'}: Unexpected token ''', "{"a": 'b'}" is not valid JSON
Older V8 (Node.js 18 and earlier, Chrome of the same era)SyntaxError: Unexpected token ' in JSON at position 1
FirefoxSyntaxError: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data
SafariSyntaxError: JSON Parse error: Single quotes (') are not allowed in JSON
Python json.loadsjson.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1), or Expecting value for a single-quoted value
Go encoding/jsoninvalid character '\'' looking for beginning of object key string
Java (Jackson)Unexpected character (''' (code 39)): was expecting double-quote to start field name

Jackson can be told to accept them with JsonReadFeature.ALLOW_SINGLE_QUOTES, and some other libraries have a similar "lenient" mode. That only moves the problem: the next system in the chain still expects real JSON.

Where single-quoted "JSON" comes from

Convert safely in code

Python, when the text is a dict repr:

import ast, json
fixed = json.dumps(ast.literal_eval(text))

JavaScript, when the text is JSON5-style (single quotes, unquoted keys, trailing commas):

import JSON5 from "json5";
const fixed = JSON.stringify(JSON5.parse(text));

Both parse the text properly, so they handle apostrophes correctly. Python keeps large integers exact, but JSON5.parse rounds anything above 253 − 1, just as JSON.parse does. The converter on this page keeps big numbers exactly as written.

FAQ

Can JSON use single quotes?

No. The JSON standard (RFC 8259) defines a string as text between double quotation marks, and object keys must be strings. JSON.parse, Python's json module, Go, Java and every other strict parser reject single quotes. JSON5 and JavaScript object literals allow them, but those are not JSON.

How do I escape a single quote (apostrophe) in JSON?

You do not need to. Inside a double-quoted JSON string an apostrophe is an ordinary character: "It's fine" is valid. Writing \' is actually an error, because the only escapes JSON allows are \" \\ \/ \b \f \n \r \t and \uXXXX. If you must avoid the character, use \u0027.

Why does replacing every ' with " break my JSON?

Because apostrophes and quotes inside the text get replaced too. 'It\'s' turns into "It\"s", which is valid JSON but now contains a double quote instead of an apostrophe, and a Python value like "It's" turns into "It"s", which no longer parses. Convert by reading each string, as this tool or ast.literal_eval does.

How do I fix single quotes in JSON from Python?

The text is a Python repr, not JSON. If you have the object, use json.dumps(obj). If you only have the text, use json.dumps(ast.literal_eval(text)), or paste it into the Python dict to JSON converter, which also handles True, None, tuples and datetime.

Does JSON5 allow single quotes?

Yes. JSON5 allows single-quoted strings, unquoted keys, trailing commas and comments. If you control both sides, you can parse it with the json5 package. Most APIs and libraries only accept strict JSON, so convert it before sending.

Why does curl send my JSON with single quotes?

Usually because the shell quoting was swapped. In bash and zsh, wrap the body in single quotes and use double quotes inside: curl -d '{"name": "Ada"}'. Writing -d "{'name': 'Ada'}" sends single quotes, and the server rejects them.