JSONDecodeError: Expecting property name enclosed in double quotes

Right after { or after a comma inside an object, JSON requires a key in double quotes. Python reports anything else at that spot with this message. At line 1 column 2 (char 1) it is nearly always a Python dict that was printed with single quotes instead of serialized; further into the text it is usually a trailing comma or an unquoted key.

Seen as:

  • json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
  • json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 5 column 1 (char 68)
  • requests.exceptions.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
  • json.decoder.JSONDecodeError: Illegal trailing comma before end of object: line 4 column 18 (char 66)

Input

Settings

History

Load from URL

Common causes

1. A dict converted with str() instead of json.dumps()

str(d), print(d), f-strings and logging all produce Python syntax with single quotes. The receiving side then fails on the first key. Serialize with json.dumps.

Before
r.set("order:1182", str(order))
After
r.set("order:1182", json.dumps(order))

2. A trailing comma before the closing brace

After a comma Python expects another key. Python 3.13 and later report this case as “Illegal trailing comma before end of object” instead.

Before
{"order_id": 1182, "paid": true,}
After
{"order_id": 1182, "paid": true}

3. Unquoted keys from JavaScript

JavaScript object literals such as {orderId: 1182} are not JSON. Quote every key, or have the JavaScript side send JSON.stringify(obj).

Before
{orderId: 1182, paid: true}
After
{"orderId": 1182, "paid": true}

4. Data that is really a Python literal

If a file or column already contains Python-style text, do not patch the quotes with replace; it breaks on apostrophes. Read it with ast.literal_eval once and write proper JSON back.

Before
data = json.loads(row["payload"].replace("'", '"'))
After
data = ast.literal_eval(row["payload"])
row["payload"] = json.dumps(data)

Frequently asked questions

Why not just replace ' with "?

A blind replace breaks strings that contain apostrophes, such as “O’Brien”, and leaves True and None in place. Use ast.literal_eval to read Python literals, or Fix it in PasteKit, which understands the string boundaries.

Can Python's json module accept single quotes?

No, and it has no option for it. Third-party parsers such as json5 or demjson accept relaxed syntax, but fixing the producer is more reliable.

Is this the same as the JavaScript error "Expected property name or '}'"?

Yes, it is the same rule reported by a different parser. The JavaScript version of this error covers browser and Node wording.

Related