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.
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.
{
"colors": [
"red",
"green",
],
"count": 2,
}{
"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.jsonand VS Code settings are JSONC, which is why your editor accepts them there andJSON.parsedoes 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.