Skip to main content

JSONDecodeError: Expecting property name enclosed in double quotes

Paste the text you passed to json.loads and click Validate to find the quote that breaks it

14
Loading editor…

What the error means

In JSON, every key must be a string in double quotes. When the parser reaches the position where a key should start and sees anything else, such as a single quote, a bare word or a closing brace after a comma, it raises this error and reports the line, column and char offset. For '{'a': 1}' the position is char 1, the opening single quote.

The editor above opens on a Python-style dictionary. Click Validate and it stops at the first single quote, the same spot Python reports.

Causes and fixes

Look at the character at the reported position and match it to one of these.

Single-quoted keys: a Python dict printed as text

Error: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

Invalid

{'name': 'Ada', 'admin': True, 'manager': None}

Fixed

{"name": "Ada", "admin": true, "manager": null}

str(d) and print(d) give Python syntax: single quotes, True, False and None. Create JSON with json.dumps(d). If you were handed Python-syntax text and cannot change the source, ast.literal_eval(text) reads it safely, and json.dumps turns the result into JSON.

Unquoted key

Error: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

Invalid

{name: "Ada"}

Fixed

{"name": "Ada"}

JavaScript allows bare keys in object literals; JSON does not. Put every key in double quotes.

Trailing comma in an object (Python before 3.13)

Error: Expecting property name enclosed in double quotes: line 1 column 9 (char 8) (Python 3.13: Illegal trailing comma before end of object)

Invalid

{"a": 1,}

Fixed

{"a": 1}

After a comma the parser expects another key, and finds the closing brace. Remove the last comma. Python 3.13 names the problem directly.

JSON written by hand or copied from a JavaScript file

Error: Expecting property name enclosed in double quotes

Invalid

{
  // settings
  "debug": true
}

Fixed

{
  "debug": true
}

Comments are not JSON either. Config files that allow them (VS Code settings, tsconfig.json) use a looser format called JSONC that Python's json module does not read.

Python raises this when it expects the name of a key in an object and does not find a double-quoted string. It is almost always single quotes, which usually means the text was produced by printing a Python dictionary rather than by json.dumps.

Frequently Asked Questions

Why does my dictionary print with single quotes?

print() shows a dictionary's Python representation, which uses single quotes and the names True, False and None. That is not JSON. Use json.dumps(my_dict) when you need JSON text, for example to send in a request body or write to a file.

Can I just replace the single quotes with double quotes?

A blind replace breaks as soon as a string contains an apostrophe, and it leaves True, False and None unfixed. Prefer ast.literal_eval to read Python-syntax text, then json.dumps to write JSON.

Why do I get this error from requests or an API response?

The server returned something that looks like JSON but was built from a Python dict, or you are parsing a string you built yourself with str(). Print the raw response text and check the quotes at the reported position.

Does the error mean the key is missing?

No. It means the parser expected a key at that position and found something that cannot start one. The cause is the character at the reported position, not a missing field.

Have suggestions or feedback? We're constantly improving FormatChamp based on your comments.