Single vs Double Quotes in JSON: Why It Matters

If you’ve ever run into a parse error where the cause was “used single quotes instead of double,” it might seem like a small detail. But this rule has a real technical reason behind it, and understanding it helps avoid a mistake that keeps coming back, especially for people who move between different languages day to day.

This post goes a bit beyond “use double quotes”: it explains why the spec is this way, and why the confusion is so common, especially with Python.

The JSON rule is simple and has no exceptions

The JSON spec (RFC 8259) defines that strings must be delimited exclusively by double quotes ("). There’s no alternative option, no “compatibility mode” for single quotes. This applies to both keys and string values.

// json
{"name": "test"}

That’s the only valid format. It doesn’t matter which language generated that JSON, or which language is going to consume it afterward. The spec is the same everywhere.

Why this confuses Python users so much

If you write Python, you’ve probably written a dictionary like this:

# python
data = {'name': 'test'}

Single quotes are perfectly valid in Python, and even common (many style guides default to single quotes). The problem is that a Python dictionary isn’t the same thing as JSON, even though it looks nearly identical.

# python
import json

data = {'name': 'test'}
json.dumps(data) # produces '{"name": "test"}', with double quotes

Python’s json module already knows how to convert the dictionary’s single quotes into double quotes when generating the JSON string. The error usually shows up when someone skips that conversion and tries to use the Python dictionary directly as if it were already a valid JSON string, for example by pasting it manually somewhere that expects real JSON.

# python
# This is NOT the same as generating JSON correctly
text = str(data) # "{'name': 'test'}", still single quotes
json.loads(text) # error: single quotes aren't valid JSON

str() just turns the dictionary into text, without caring about JSON syntax. To generate real JSON, the correct path is always json.dumps().

The same applies to JavaScript

// javascript
const obj = { name: 'test' }; // valid in JS, single quotes
JSON.stringify(obj); // produces '{"name":"test"}', with double quotes

Again, the JavaScript object itself accepts single quotes just fine. What needs double quotes is the generated JSON string, and that’s JSON.stringify()‘s job, not the original object’s.

How to fix a JSON that already has single quotes

If you received text with single quotes that’s supposed to be JSON (for example, copied from somewhere or saved incorrectly), the fix isn’t a naive find-and-replace of single quotes for double quotes. That breaks any apostrophe inside the values.

// javascript
// Risky: replaces every single quote, including ones that are part of the text
text.replace(/'/g, '"');
// "It's a test" would become "It"s a test", breaking everything

The safer path is rebuilding the object correctly in the source language, then generating the JSON with the proper function (JSON.stringify() in JS, json.dumps() in Python), instead of trying to patch the string by hand.

Quick checklist

  • Does the final JSON use double quotes on every key and string value?
  • If you generated the JSON from a Python dictionary or JavaScript object, did you use json.dumps() or JSON.stringify() (not str() or manual concatenation)?
  • Did you avoid doing a direct find-and-replace of single quotes for double quotes on the final string?

If you’re unsure whether a JSON is in the right format, paste it into JSON Formatter & Validator to confirm before using it in production.