SyntaxError: Expected property name or '}' in JSON

After { or a comma inside an object, JSON requires a key written as a double-quoted string. Anything else at that spot, such as a bare word, a single quote or a comment, produces this error. It usually means the text is a JavaScript object literal rather than JSON. Python reports the same problem as “Expecting property name enclosed in double quotes”.

Seen as:

  • SyntaxError: Expected property name or '}' in JSON at position 4 (line 2 column 3)
  • SyntaxError: Unexpected token n in JSON at position 4
  • SyntaxError: JSON.parse: expected property name or '}' at line 2 column 3 of the JSON data
  • json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 3 (char 4)

Input

Settings

History

Load from URL

Common causes

1. Unquoted keys from a JavaScript object literal

JavaScript lets you write { name: "Ada" }; JSON does not. Every key must be in double quotes. If the text came from console.log, copy it with JSON.stringify(value, null, 2) instead.

Before
{ name: "Ada Lovelace", email: "ada@example.com" }
After
{ "name": "Ada Lovelace", "email": "ada@example.com" }

2. Keys in single quotes

Single-quoted keys are valid in JavaScript and Python but not in JSON. Replace both quotes of every key and string value with double quotes.

Before
{'name': 'Ada Lovelace', 'admin': true}
After
{"name": "Ada Lovelace", "admin": true}

3. A comment where a key should be

A // or /* comment at the start of a line inside an object is read as the start of a key. JSON has no comments; remove them or parse the file as JSONC.

Before
{
  // primary contact
  "email": "ada@example.com"
}
After
{
  "email": "ada@example.com"
}

4. A comma after the last property (newer wording)

Current Chrome and Node phrase this case as “Expected double-quoted property name”. The comma promises another key, so the parser finds } instead. See trailing commas in JSON.

Before
{"email": "ada@example.com", "admin": true,}
After
{"email": "ada@example.com", "admin": true}

Frequently asked questions

Is this the same error as "Expecting property name enclosed in double quotes"?

Yes. That is Python’s wording for the same problem; see the Python version of this error for causes specific to Python dicts.

Why did older Chrome versions say "Unexpected token n"?

Before Chrome 117 and Node 20, V8 reported the first character of the bad key, so an unquoted name key gave “Unexpected token n in JSON at position N”. The newer message describes what was expected instead.

Can I keep unquoted keys?

Only if you switch format. JSON5 allows unquoted keys, single quotes and comments, and PasteKit can convert JSON5 to strict JSON in one step.

Related