How to Fix a Trailing Comma in JSON
Strict JSON permits commas between members or items. A final comma before ] or } can be valid in a JavaScript source literal but is rejected by a strict JSON parser.
Worked example
Invalid JSON with two trailing commas
{"name":"Maya","items":[1,2,],}Corrected result from the formatter
{
"name": "Maya",
"items": [
1,
2
]
}Steps
- Use the formatter's Validate mode to find the failing location. Start with the bracket or brace nearest the reported position.
- Remove only the separator after the final item or member. Keep commas between items and inside quoted strings.
- Validate the corrected file, then format it so the closing brackets and nesting are easy to review.
What to check
- Revalidate the entire document after fixing the first error. A second trailing comma can be hidden by the earlier failure.
- If the source is JSONC or JavaScript, use a parser for that format to produce strict JSON for interchange.