JSON Error: Trailing Comma
SyntaxError: Unexpected token } in JSON at position XWhat Causes This Error?
A trailing comma is a comma placed after the last element in a JSON object or array, immediately before the closing } or ] bracket. JSON (RFC 8259) strictly forbids trailing commas, unlike JavaScript which allows them. This is the single most common JSON error — especially when developers copy from JavaScript object literals or remove a property and forget to clean up the comma above it.
Common Causes
- arrow_rightRemoving a key-value pair from a JSON object but leaving its preceding comma
- arrow_rightAdding a new property and putting a comma at the end of it
- arrow_rightCopying from a JavaScript object literal that had trailing commas
- arrow_rightCode generators that don't strip trailing commas when outputting JSON
- arrow_rightAdding an item to a JSON array and forgetting that the last item must have no comma
Example: Broken vs Fixed JSON
cancel Invalid JSON (causes the error)
{
"users": [
{"name": "Alice", "role": "admin"},
{"name": "Bob", "role": "editor"},
],
"count": 2,
}check_circle Fixed JSON (valid)
{
"users": [
{"name": "Alice", "role": "admin"},
{"name": "Bob", "role": "editor"}
],
"count": 2
}Step-by-Step Fix Guide
Find the closing bracket
Look for every } or ] in your JSON. The trailing comma will be on the line just above it.
Remove the comma
Delete the comma after the last key-value pair before each } and the last element before each ]. Do not remove any other commas — only the ones directly before a closing bracket.
Use Find & Replace (for large files)
In VS Code, search for ",\n}" and ",\n]" with regex enabled to find all trailing comma locations at once.
Validate
Paste the cleaned JSON into the JSON Validator. If trailing commas were the only issue, it will now show valid.
Fix This Error Instantly
Paste your JSON into the validator to get the exact line number and error description. Then use the JSON Editor to make the fix and re-validate in one workflow.
Related JSON Errors
Part of the JSON Toolkit
Explore All JSON Tools
Free online tools for every JSON task — format, validate, convert, compare, and more.