Unquoted property names in JSON

In JSON an object member is a *string* followed by a colon. There is no bare-identifier form, so {name: "Ada"} is invalid however ordinary the key looks.

How the message appears

The same fault, worded by different engines. V8 (Chrome, Node, Edge) changed its format around Chrome 109, so older and newer runtimes disagree about the same document.

  • SyntaxError: Expected property name or '}' in JSON at position 2
  • SyntaxError: JSON.parse: expected double-quoted property name at line 2 column 3 of the JSON data

What causes it

A JavaScript object literal used as JSON

JavaScript allows unquoted keys when they are valid identifiers, so {name: "Ada"} is fine in a .js file and invalid in a .json one. The two syntaxes look similar enough that this is easy to miss in review.

YAML or an env-style file being parsed as JSON

If the whole document uses key: value with no braces or quotes, it is not malformed JSON — it is a different format, and it needs a YAML parser rather than a fix.

Hand-written fixtures

Test fixtures typed by hand rather than generated. JSON.stringify always quotes keys, so anything it produces is safe.

The fix

Wrap every property name in double quotes. Values keep their own rules — strings quoted, numbers and booleans bare.

Fails to parse
{
  name: "Ada",
  id: 7
}
Parses
{
  "name": "Ada",
  "id": 7
}

The example travels in the URL fragment, which browsers never send to a server.

Worth knowing

  • JSON5 permits unquoted keys. If you control the reader and genuinely want that, use a JSON5 parser rather than hand-relaxing JSON.
  • Keys are strings, so {"1": "a"} is legal and {1: "a"} is not, even though both work as JavaScript.

No cookies, no accounts, no tracking. Your JSON and text are processed entirely in your browser and never sent anywhere. We count anonymous page views (the page address only, nothing about you or your device), and use localStorage to remember your theme.