Why a trailing comma breaks JSON
Bottom line: Trailing commas are legal in JavaScript object literals and fatal in JSON. Here is the exact error, the RFC 8259 grammar that causes it, and three fixes that actually hold.

Bottom line: JSON forbids trailing commas everywhere — when a parser fails, delete the last comma with a formatter; use JSON5 or JSONC only for local lenient parsing, and always emit standard JSON to other systems.
Because the grammar says so.
{
"name": "demo",
"size": 12,
}
JSON.parse throws Unexpected token } in JSON at position 34. Node words it differently, but every engine points at the same place: the comma before }.
What the parser is actually complaining about
The object production in RFC 8259 is:
object = begin-object [ member *( value-separator member ) ] end-object
Square brackets mean optional, the asterisk means zero or more. In plain terms: commas separate members, and the last member is followed directly by }.
So after a comma the parser is ready for another member name. It reads } and fails. Arrays behave identically — [1, 2, 3,] fails at the ].
Where the habit comes from
JavaScript object literals have allowed trailing commas since ES5, as do Python lists and Go composite literals. Editors add them automatically. Then someone copies an object literal out of a .js file into a .json file and the file stops parsing.
The other common source is hand-built JSON: a loop that runs i <= length leaves a comma after the final element.
Three fixes
Remove the comma. Fine for manual edits. Paste into the JSON formatter and the error is reported with line and column, so you can see exactly which one to delete.
Parse as JSON5. Supersets accept trailing commas, which is fine for local config. It is not fine for anything you send to another system — the receiver will still reject it.
Stop concatenating strings. Use JSON.stringify, json.dumps, Jackson. The serializer handles separators correctly and solves escaping at the same time.
Quick audit list
| Where | Typical cause |
|---|---|
| Loop concatenation | i <= length leaves one extra comma |
| Copy-paste | Object literal lifted from a JS file |
| Templates | Hardcoded comma plus a loop that adds another |
| Manual edit | Last field deleted, its comma left behind |
FAQ
Why are trailing commas legal in JavaScript but not in JSON?
JavaScript object literals have allowed them since ES5, and so do Python lists and Go composite literals, which is why the habit follows people into JSON. RFC 8259 permits commas only between members: the last member is followed directly by } or ]. Copying an object literal out of a .js file into a .json file is the usual source.
Should I parse as JSON5 to accept trailing commas?
Only for local configuration. Supersets accept trailing commas, but anything you send to another system is parsed as strict JSON and will still fail. Generate standard JSON at the output boundary instead of relying on the receiver to be lenient.
Where should I look first after a trailing comma error?
Start with the position in the error message: it usually points at the comma before } or ]. Then check the three usual sources: a loop written with i <= length, an object literal pasted from a JS file, and a template that hardcodes a comma alongside a loop. Pasting into a formatter reports the exact line and column.