Are Single Quotes Allowed in JSON?
No. Single quotes are not valid in JSON. JSON requires double quotes for all keys and string values.
JSON strictly requires double quotes according to the official specification.
If you see errors like Unexpected token ' or parsing failures, this is usually the cause.
Invalid JSON:
{'name': 'Sam', 'age': 30}Valid JSON:
{"name": "Sam", "age": 30}Paste your JSON into the validator to detect and fix quote errors instantly using the JSON Validator.
JSON only accepts double quotes. Using single quotes will cause invalid JSON errors in most parsers. It does not matter what language you came from. If a key or string value is wrapped in single quotes, the parser rejects the whole payload. Here is what is happening, what the error looks like in each runtime, and how to fix it without breaking apostrophes.
Why the spec is this strict
JSON was designed to be boring on purpose. One part of that is strict quoting. Every parser, in every language, can agree on what counts as a string because the format only accepts double quotes.
JavaScript is what makes this feel slippery. In a JavaScript object literal, single quotes are fine. But a JavaScript object literal is not JSON. The moment that payload goes through JSON.parse(), json.loads(), or an API request body, the JSON rules win.
Invalid vs valid, side by side
These are the three versions people hit most often when they are copying JSON by hand or pasting code from another language.
Invalid: all single quotes
Both keys and values are wrapped incorrectly here.
Invalid: one single-quoted value is enough
Even one single-quoted string makes the whole payload invalid.
Valid: double quotes throughout
Once the keys and string values use double quotes, the parser is happy again.
What the error looks like per runtime
The exact message changes, but the root cause is always the same. The parser found a single quote where JSON only allows a double quote.
| Runtime | Error message | What it means |
|---|---|---|
JSON.parse | Unexpected token ' in JSON at position 2 | A key or string started with a single quote instead of a double quote. |
json.loads | Expecting property name enclosed in double quotes | Python is telling you the string looks like a dict literal, not strict JSON. |
API client | Invalid JSON near key or opening character | The parser stopped at the first place where the quote style made the payload invalid. |
The same mistake looks different in each language
The rule never changes. What changes is the mental trap that gets you there. Pick the language you are coming from and compare the failing pattern with the safe one.
Python is the most common case. Dict literals use single quotes naturally, so it is easy to forget that json.loads parses strict JSON, not Python syntax.
Classic Python mistake
This string looks like a Python dict literal, but it is still invalid JSON.
Let json.dumps handle the quoting
If you start from a dict, serialize it instead of hand-writing JSON text.
JavaScript object literals and JSON are close cousins, which is exactly why this error shows up so often. Valid JS syntax is not automatically valid JSON text.
Copied from JS source, breaks as JSON
Single-quoted strings are fine in JS source, but not inside JSON.parse input.
Serialize instead of hand-editing
JSON.stringify always emits valid double-quoted JSON.
PHP string delimiters and JSON delimiters are two different things. Wrapping a PHP string in single quotes does not make the JSON inside that string single-quote-safe.
Single-quoted JSON content is still invalid
json_decode expects strict JSON inside the string.
Generate JSON from real data
Use json_encode so PHP handles the quoting rules for you.
curl is confusing because shell quotes and JSON quotes sit next to each other. The shell can use single quotes outside while the JSON inside still uses double quotes.
Shell quotes outside, JSON quotes inside
The outer single quotes belong to the shell. The JSON payload is still using double quotes correctly.
What actually breaks the payload
Here the JSON itself is wrong, even though the shell command is quoted.
How to fix it without breaking your data
A blind find-and-replace on ' to " is how people turn one parse error into two. Work in order instead.
- 1Identify the scope first. Are the keys wrong, the values wrong, or both?
- 2Replace only the single quotes acting as JSON delimiters.
- 3Leave apostrophes inside real text alone.
- 4Validate again immediately so hidden follow-up errors show up before you move on.
Apostrophes inside strings are still valid
This is valid because the string itself is still wrapped in double quotes.
Quick answers
What to do next
Start with the validator if the payload still fails. Once it passes, move to the formatter or jump sideways into the adjacent error guides.
Use JSON Validator
Paste the payload and see exactly which line is breaking the parse.
Use JSON Formatter
Once the quotes are fixed, format the corrected JSON into clean, readable output.
Back to Common JSON Errors
Return to the overview page for this JSON error family and branch into the matching fix.
Unexpected Token in JSON
Unexpected token in JSON usually means the parser found a character it did not expect. See the common causes and how to trace the real syntax mistake.
JSON Parse Error Line and Column
JSON parse error line and column messages help narrow the search, but the real syntax issue can be slightly earlier. Learn how to read the location properly.