JSON errors

Python, from json.loads() and json.load()

Expecting property name enclosed in double quotes

Python's json module found something other than a double-quoted key where a key should start. The text is almost always a Python dict printed with str() or repr(), which uses single quotes, or a JavaScript object with bare keys.

How each browser and language words it

Python json module
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
Python 3.12 and below, for {"a": 1,}
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 9 (char 8)
JavaScript
SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)

Paste your JSON to find the exact line

A Python dict printed with str(). Press Repair to convert the quotes and turn True and None into true and null.

Skip to editor
Explorer
Open Files

No files open

0 files open

jsoneditor.io v2

{'id': 7, 'name': 'Ada Lovelace', 'roles': ['admin', 'editor'], 'active': True, 'manager': None}
JSONUTF-8
Spaces: 2

Causes and how to fix each one

1. The text came from str(dict) or print

Python prints dicts with single quotes and True, False and None, none of which are JSON. Write JSON with json.dumps, and if you're stuck with dict text from somewhere else, ast.literal_eval reads it safely.

Python
import ast
import json

text = "{'id': 7, 'active': True, 'manager': None}"

data = ast.literal_eval(text)  # reads Python literal syntax safely
print(json.dumps(data))        # {"id": 7, "active": true, "manager": null}

2. A trailing comma on Python 3.12 and below

Before Python 3.13 a trailing comma also produced this message, pointing at the closing brace. Python 3.13 and newer say Illegal trailing comma before end of object instead. Remove the comma after the last item.

3. Keys without quotes

JavaScript-style objects like {id: 7} need every key wrapped in double quotes before json.loads will accept them.

Questions people ask

Should I use eval to read a dict string?

No, eval runs any code in the string. ast.literal_eval only accepts literals like dicts, lists, strings and numbers, so it is safe for untrusted text.

Why does json.dumps output differ from print?

print uses Python repr formatting, json.dumps writes the JSON format: double quotes, true, false and null. Only the json.dumps output can be read by other languages.

Tools for this