# Expecting property name enclosed in double quotes (Python)

> Fix Expecting property name enclosed in double quotes in Python: str(dict) and single quotes, trailing commas, comments, unquoted keys, smart quotes.

- URL: https://jsonstatham.dev/errors/expecting-property-name/
- Language: English (en)
- Russian version: https://jsonstatham.dev/ru/errors/expecting-property-name.md
- Updated: 2026-11-08

`json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)` means Python’s `json` was inside an object, right after `{` or a comma, and the next character was not `"`. JSON keys wear double quotes. This one didn’t, or there was no key at all. Most often the text isn’t JSON but a Python dict printed with `str()`.

## What sits at that position

Look at the character at `char N`, counting from 0. It is one of five things:

| Text | Python 3.9.6 | Python 3.14.10 | Cause |
| --- | --- | --- | --- |
| `{'id': 42}` | `Expecting property name enclosed in double quotes: line 1 column 2 (char 1)` | the same | Single quotes, usually from `str(dict)`: [single quotes](https://jsonstatham.dev/errors/single-quotes/) |
| `{"id": 42,}` | `Expecting property name enclosed in double quotes: line 1 column 11 (char 10)` | `Illegal trailing comma before end of object: line 1 column 10 (char 9)` | [Trailing comma](https://jsonstatham.dev/errors/trailing-comma/) |
| `{`, then `// user id` on the next line | `Expecting property name enclosed in double quotes: line 2 column 3 (char 4)` | the same | [Comment](https://jsonstatham.dev/errors/comments/) |
| `{id: 42}` | `Expecting property name enclosed in double quotes: line 1 column 2 (char 1)` | the same | [Unquoted key](https://jsonstatham.dev/errors/unquoted-key/) |
| `{“id”: 42}` | `Expecting property name enclosed in double quotes: line 1 column 2 (char 1)` | the same | [Smart quotes](https://jsonstatham.dev/errors/smart-quotes/) from a word processor or a chat |

Python 3.13 changed one case. A trailing comma now has its own message and points at the comma itself, one character earlier; Python 3.12 and older report `Expecting property name` at the `}` that follows. Compare `Lib/json/decoder.py` in [3.12](https://github.com/python/cpython/blob/3.12/Lib/json/decoder.py) and [3.13](https://github.com/python/cpython/blob/3.13/Lib/json/decoder.py).

[RFC 8259](https://www.rfc-editor.org/rfc/rfc8259) is explicit: “A name is a string”, and a string “begins and ends with quotation marks”, the `"` character (`%x22` in its grammar). Single quotes, bare words and comments don’t qualify, and after a comma another member has to follow.

## The usual suspect: str(dict)

A dict printed with `str()`, `print()`, an f-string or `%s` logging looks like JSON and isn’t: single quotes, `True`, `None`. `json.dumps` writes the real thing:

```python
import json

payload = {"id": 42, "ok": True, "tags": None}
print(str(payload))         # {'id': 42, 'ok': True, 'tags': None}
print(json.dumps(payload))  # {"id": 42, "ok": true, "tags": null}
```

Where a dict gets turned into text by mistake:

- `requests.post(url, data=str(payload))`. Send `json=payload` instead: requests serializes it and sets `Content-Type: application/json`.
- `f.write(str(data))` instead of `json.dump(data, f)`.
- A message queue, a cache or a database column filled with `str(obj)`.
- Another program gluing strings together with single quotes. Every language has a serializer; see [the table below](https://jsonstatham.dev/errors/expecting-property-name/#producers).
- Windows `cmd.exe`, where single quotes don’t quote: `curl -d '{"id": 42}'` arrives mangled. Put the body in a file and send it with `-d @body.json`.

Don’t repair the text with `.replace("'", '"')`. It breaks on any apostrophe inside a value and leaves `True` and `None` behind; on the payload above the next error is `Expecting value: line 1 column 18 (char 17)`. If the producer really is Python and you can’t change it, read its output as a Python literal, not as JSON:

```python
import ast

data = ast.literal_eval(text)
```

[`ast.literal_eval`](https://docs.python.org/3/library/ast.html#ast.literal_eval) evaluates literals and nothing else (dicts, lists, strings, numbers, `True`, `None`), but it is meant for Python output you trust, not for arbitrary input.

## Producing real JSON in other languages

When the text comes from another program, fix it there. Every call in the middle column was run and returns `{"id":42}`; Python adds a space after the colon.

| Language | Do this | Not this |
| --- | --- | --- |
| JavaScript | `JSON.stringify({ id: 42 })` | `"{'id': " + id + "}"` |
| Python | `json.dumps({"id": 42})` | `str({"id": 42})` |
| Go | `json.Marshal(map[string]any{"id": 42})` | `fmt.Sprintf("{'id': %d}", id)` |
| Java (Jackson) | `mapper.writeValueAsString(Map.of("id", 42))` | `"{'id': " + id + "}"` |
| C# | `JsonSerializer.Serialize(new { id = 42 })` | `$"{{'id': {id}}}"` |
| PHP | `json_encode(['id' => 42])` | `"{'id': $id}"` |

## Comments and trailing commas in hand-written files

Configuration files edited by people collect `//` comments and trailing commas. Both are allowed in JSONC and [JSON5](https://json5.org/); both are rejected by `json`. Remove them, or read the file with a parser for the format it is really in:

```python
import json5  # pip install json5

data = json5.loads(text)
```

Checked with json5 0.17.3: comments, trailing commas, unquoted keys and single quotes all load. The trade-offs are in [comments in JSON](https://jsonstatham.dev/guides/json-comments/).

## Find the character

The exception carries the position as numbers. Print the line with a caret under the column:

```python
try:
    data = json.loads(text)
except json.JSONDecodeError as e:
    line = text.splitlines()[e.lineno - 1]
    print(f"{e.msg} at line {e.lineno}, column {e.colno}")
    print(line)
    print(" " * (e.colno - 1) + "^")
```

For a comment on the third line this prints `Expecting property name enclosed in double quotes at line 3, column 3`, then the line `  // owner`, then a caret under the first slash.

## The same input in other parsers

`{'id': 42}` fed to every parser available for the check. Two of them accept it, which is how such text survives until it reaches Python:

| Parser, version checked | Message | Note |
| --- | --- | --- |
| Chrome 156, Node.js 25.1 (V8) | `SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)` | Node.js 20 prints it without the line and column |
| Node.js 18.20 (V8 10.2) | `SyntaxError: Unexpected token ' in JSON at position 1` | The older wording |
| Firefox (source: SpiderMonkey) | `SyntaxError: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data` |  |
| Safari, JavaScriptCore of macOS 27.0.1 | `SyntaxError: JSON Parse error: Single quotes (') are not allowed in JSON` | The only one that names the problem |
| Go 1.25.3 | `invalid character '\'' looking for beginning of object key string` |  |
| Java, Jackson 2.20.1 | `Unexpected character (''' (code 39)): was expecting double-quote to start field name` |  |
| Java, Gson 2.13.2 | no error | `fromJson` reads single quotes leniently |
| C#, System.Text.Json 10 (runtime 10.0.14) | `''' is an invalid start of a property name. Expected a '"'.` | Followed by `LineNumber: 0 \| BytePositionInLine: 1.` |
| C#, Newtonsoft.Json 13.0.4 | no error | Accepts single quotes and trailing commas |
| PHP 8.5.12 | `Syntax error` | Code 4 |
| jq 1.7.1 | `jq: parse error: Invalid numeric literal at line 1, column 6` |  |
| jq 1.8.2 | `jq: parse error: Invalid string literal; expected ", but got ' at line 1, column 6` |  |
| FastAPI 0.128.8, as the server | `422` with `"msg":"JSON decode error"` and `"error":"Expecting property name enclosed in double quotes"` | The Python message reaches the client inside the response |
| Flask 3.1.3, as the server | `400 Bad Request` as an HTML page | The client then fails with [Unexpected token '<'](https://jsonstatham.dev/errors/unexpected-token/) |

## Try it

Open the validator with a [single-quoted](https://jsonstatham.dev/validator/?sample=single_quotes) or a [trailing-comma](https://jsonstatham.dev/validator/?sample=trailing_comma) sample to see how each is reported: the error names the character and gives its line and column.

Related: [Expecting value](https://jsonstatham.dev/errors/expecting-value/), [comments in JSON](https://jsonstatham.dev/guides/json-comments/), and the [list of JSON errors](https://jsonstatham.dev/errors/).

## Expecting property name FAQ

### What does “Expecting property name enclosed in double quotes” mean?

Inside an object, after `{` or a comma, Python expected a key in double quotes and found something else: a single quote, the closing brace after a trailing comma, a comment or a bare word.

### How do I convert a Python dict to JSON?

`json.dumps(d)` for a string, `json.dump(d, f)` for a file. Never `str(d)`: it writes single quotes, `True` and `None`.

### Can Python’s json accept single quotes?

No, and there is no option for it. Fix the producer. If the text is Python output you trust, use `ast.literal_eval`; for a hand-written config, a JSON5 parser.

### Why does the same file fail differently on Python 3.13?

Python 3.13 reports a trailing comma as `Illegal trailing comma before end of object` and points at the comma; older versions report `Expecting property name` at the brace after it.
