Errors · JSON

Trailing comma in JSON

A comma after the last value of an object or an array. JavaScript, JSON5 and most config dialects allow it; JSON does not, and every parser stops at the bracket after it.

no signup · runs entirely in your browser · ⌘V works anywhere on this page

What each parser says

The sample below, unchanged, through three parsers. The message is the same break in three wordings; the line or position each names is where the parser gave up, not always where the break is.

Node and Chrome (V8), measured when this page was built
Unexpected token ']', ...", "trace",], "debu"... is not valid JSON
Python 3.14 json.loads, measured 2026-09-06
Illegal trailing comma before end of array: line 4 column 32 (char 75)
jq 1.7, measured 2026-09-06
jq: parse error: Expected another array element at line 4, column 33

The fix, measured

In an object
{"a": 1, "b": 2,}{"a": 1, "b": 2}
In an array
[1, 2, 3,][1, 2, 3]
The whole sample
{ "name": "checkout-api", "port": 8080, "features": ["retry", "trace",], "debug": false, }{ "name": "checkout-api", "port": 8080, "features": ["retry", "trace"], "debug": false }

2 fixes, both named “Remove trailing comma”; every other byte stays.

Where the parser points

Every parser points at the character after the comma — the closing bracket — because that is where it gave up. The comma before it is the break; the fix removes that comma and nothing else, and says so on its line.

The sample

What the first sample opens — a real file, not an illustration written for this page.

config.json
{
  "name": "checkout-api",
  "port": 8080,
  "features": ["retry", "trace",],
  "debug": false,
}

Questions

Why does JavaScript allow it and JSON not?

JSON is a subset of JavaScript’s literal syntax, frozen in 2001 before trailing commas were common. JSON5 and JSONC allow them again; a JSON parser does not, so an object copied out of source code breaks at the first one.

Where did the trailing comma come from?

A hand edit that deleted the last line but not the comma before it, a code formatter that writes them on purpose, or a printed Python or JavaScript object.

Can it be fixed automatically?

Yes, and only that: the fix removes the comma before a closing bracket, one per line, and leaves every other byte as pasted. Nothing is reordered or reformatted.

Try it on the file that broke your afternoon.

free while in alpha · no signup