{}JSON FYI

Expecting property name enclosed in double quotes — fix

Python's "Expecting property name enclosed in double quotes" means single quotes, a trailing comma, or a Python dict — the fix for each.

·6 min read

What does "Expecting property name enclosed in double quotes" mean?

Python's json.loads() raises this JSONDecodeError when it expects an object key but finds something that is not a double-quoted string. The four usual causes are single-quoted keys (often a Python dict printed with str()), a trailing comma before }, unquoted keys copied from a JavaScript object literal, or a comment inside the JSON. The column number tells you which.

Read the column number first

Python reports the exact offset. Where it points narrows the cause immediately:

# Single quotes or an unquoted key — fails right after the opening brace
>>> json.loads("{'name': 'Ada'}")
JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

# Trailing comma — fails deeper in, at the comma before }
>>> json.loads('{"a": 1,}')
JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 9 (char 8)

Column 2 (char 1) — the very first key is wrong: single quotes, an unquoted name, or a stray character right after {. A column deep inside the object — a comma is followed by } or another comma instead of the next "key".

Cause 1 — single-quoted keys (the most common)

JSON requires double quotes around every key and every string. Single quotes are not valid JSON, even though Python and JavaScript accept them in source code.

# ✗ Fails at column 2 — single quotes
json.loads("{'name': 'Ada'}")

# ✓ Correct — double quotes throughout
json.loads('{"name": "Ada"}')

Cause 2 — a Python dict passed as a string

This is the hidden version of Cause 1. Calling str() (or an f-string, or print) on a Python dict produces single-quoted text that looks like JSON but is not. Feeding that back into json.loads() fails.

d = {"name": "Ada"}
json.loads(str(d))          # str(d) is "{'name': 'Ada'}"  → ✗ fails

# ✓ You already have the dict — just use it, no parsing needed
d["name"]                   # 'Ada'

# ✓ Need JSON text? Build it with json.dumps, never str()
json.loads(json.dumps(d))   # round-trips correctly

# ✓ Only have a Python-literal string (not JSON)? Use ast, not json
import ast
ast.literal_eval("{'name': 'Ada'}")   # {'name': 'Ada'}

Cause 3 — a trailing comma before } or ]

JSON forbids a comma after the last member. After the comma the parser expects another key, hits the closing brace, and reports this error at the comma's column. See trailing commas in JSON for the full story.

# ✗ Trailing comma after 1
json.loads('{"a": 1,}')

# ✓ Remove it
json.loads('{"a": 1}')

Cause 4 — unquoted keys from a JavaScript object literal

JavaScript lets you write object keys without quotes; JSON does not. Text copied out of a .js file or a console log often carries bare keys.

# ✗ Bare key — valid JavaScript, invalid JSON
json.loads('{name: "Ada"}')

# ✓ Quote every key with double quotes
json.loads('{"name": "Ada"}')

Cause 5 — comments inside the JSON

JSON has no comment syntax. A // or /* */ after a brace is read as the start of a key and trips the same error. Strip comments first, or use a tolerant parser — see JSON comments.

Paste your JSON into the validator →

Get the exact line, column, and a fix hint in seconds — no upload, no signup.

Open JSON Validator →

The reliable fix: never hand-build JSON

Almost every case above comes from JSON that was typed or interpolated by hand. Generate it with a serializer and the quoting is always correct:

import json

# ✓ From a Python object → guaranteed-valid JSON text
payload = json.dumps({"name": "Ada", "roles": ["admin"]})

# ✓ Straight from an API response — decode the bytes, don't str() them
import requests
data = requests.get(url).json()   # requests parses the body for you

If the input is genuinely a Python literal rather than JSON — single quotes, True/None instead of true/null — parse it with ast.literal_eval, which understands Python syntax. For a deeper tour of every json.loads() failure mode, see Python JSONDecodeError.

Frequently asked questions

Why does Python say Expecting property name enclosed in double quotes?+

Because json.loads expected an object key — a double-quoted string — but found something else: a single-quoted key, an unquoted key, a comment, or a trailing comma that leaves no key before the closing brace. The column number in the message points at the exact spot.

How do I fix single quotes in JSON?+

JSON requires double quotes around every key and string value. Replace the single quotes with double quotes, or better, build the JSON with json.dumps() so the quoting is correct automatically. Do not use str() on a dict to produce JSON — it emits single quotes.

Why does json.loads(str(my_dict)) fail?+

str() on a Python dict produces Python's repr, which uses single quotes (e.g. {'a': 1}). That is not valid JSON. If you already have the dict, use it directly; if you need JSON text, use json.dumps(my_dict) instead of str().

The error points at line 1 column 2 — what's wrong?+

Column 2 is the character right after the opening brace, so the very first key is the problem: it is single-quoted, unquoted, or preceded by a stray character. Fix the first key and re-run.

Can I parse a Python dict string that uses single quotes?+

Not with json.loads — that requires JSON. Use ast.literal_eval() from the standard library, which safely evaluates Python literal syntax including single quotes, True/False, and None.

Does JavaScript throw the same message?+

No. This exact wording comes from Python's json module. JavaScript's JSON.parse reports something like "Unexpected token" or "Expected property name or '}'" for the same malformed input, but the causes and fixes are identical.

Related tools & guides