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.

Unexpected token ']', ...", "trace",], "debu"... is not valid JSON

Illegal trailing comma before end of array: line 4 column 32 (char 75)

jq: parse error: Expected another array element at line 4, column 33

## The fix, measured

{ "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.

```
{
  "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.

## Behind this page

## Try it on the file that broke your afternoon.

free while in alpha · no signup

---

Canonical: https://unstringify.com/errors/trailing-comma
