Trailing comma in JSON

A comma may only separate two values. A comma followed by } or ] is a syntax error in JSON, even though the identical code is legal in a JavaScript object or array literal and has been since ES5.

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: Unexpected token ']', ..."b", "c",]"... is not valid JSON
  • SyntaxError: JSON.parse: unexpected character at line 3 column 3 of the JSON data

What causes it

Hand-edited config files

Deleting the last entry from a list and leaving the comma above it. This is the single most common way a working config file breaks.

Code generation with a loop

Building JSON by string concatenation and appending a comma after every item. Use JSON.stringify or join an array instead — a serializer cannot make this mistake.

Copying from JavaScript source

Prettier and most formatters add trailing commas to JavaScript by default (trailingComma: "es5" and above). Copy such an object into a .json file and it stops parsing.

The fix

Remove the comma before ] and the comma before }. Nothing else changes.

Fails to parse
{
  "colors": [
    "red",
    "green",
  ],
  "count": 2,
}
Parses
{
  "colors": [
    "red",
    "green"
  ],
  "count": 2
}

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

Worth knowing

  • JSON5 and JSONC both allow trailing commas. tsconfig.json and VS Code settings are JSONC, which is why your editor accepts them there and JSON.parse does not.
  • Do not strip trailing commas with a naive regex — a comma inside a string value would be destroyed too. The repair in the validator parses the document rather than pattern-matching it.

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.