Trailing commas are not allowed in JSON
JSON forbids a comma after the last item of an object or array, even though JavaScript allows it. Here is why, and how to find and remove them.
Open the JSON formatterWhat the error looks like
Different engines word this differently. You may see any of these:
Why it happens
- JavaScript object and array literals permit a trailing comma, and most editors and formatters add them, so the habit carries over.
- JSON does not permit one. The grammar requires a value after every comma, so a comma followed by a closing bracket is a syntax error.
- The reported position is the closing bracket, not the comma, which is why the message can feel like it is pointing at the wrong character.
Example
{
"name": "John",
"age": 30,
}
{
"name": "John",
"age": 30
}
How this tool reports it
The formatter points at the comma itself rather than the bracket after it, and offers Remove comma as a one-click fix.
Paste your JSON into the formatter to see the exact line and column, or use the validator if you only need to check it.
Worth knowing
- JSON5 and JSONC do allow trailing commas. If a file is meant to be one of those, it is not JSON and should not be parsed as JSON.
- tsconfig.json and VS Code settings files are JSONC, which is why they tolerate both comments and trailing commas.