Fix Trailing Comma in JSON
A trailing comma after the last object property or array item is valid in some JavaScript contexts, but it is not valid JSON.
Why the Error Happens
JavaScript object literals often allow a final comma, but RFC 8259 JSON requires the final item to be followed directly by the closing bracket or brace. The error is the parser's most predictable rejection — it's a one-character bug with no ambiguity about the cause.
Broken Example
Trailing commas show up in two places — after the last property of an object, and after the last item of an array:
{
"name": "Ada",
"active": true,
"tags": ["dev", "lovelace",]
}
There are two trailing commas in that payload: one after true, one after "lovelace". A strict parser stops at the first one.
Fixed JSON
{
"name": "Ada",
"active": true,
"tags": ["dev", "lovelace"]
}
Same data, both commas removed.
How Different Languages Report It
The error message varies by parser, but the root cause and the fix are identical:
| Language / parser | Error message |
|---|---|
JavaScript (JSON.parse, V8) |
SyntaxError: Unexpected token } in JSON at position … (or Unexpected token ']') |
Python (json.loads) |
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes (object) / Expecting value (array) |
Go (encoding/json) |
invalid character '}' looking for beginning of object key string |
| jq | parse error: Expected another array element at line … |
For the JavaScript-specific variant in the Unexpected token family, see the umbrella guide — the , token row in that table points back here.
Where Trailing Commas Come From
Most appear when someone hand-edits a config, comments out the last item, or pastes from JavaScript or TypeScript source. Template engines and code generators also produce them when a loop emits a comma after every item without tracking the last index. The other common source: copying valid JSON5 or JSONC config into a JSON file without removing the comma.
Why Some Parsers Accept Them and JSON Does Not
JavaScript object literals, JSON5, JSONC (the format VS Code uses for tsconfig.json and settings.json), YAML, and most programming-language literal syntaxes allow a trailing comma because it makes diffs cleaner — adding a new item touches one line, not two. RFC 8259 JSON intentionally does not allow it. Strict parsers like JSON.parse, Go's encoding/json, and Python's json module all reject it; the spec authors prioritized parser simplicity over editing convenience.
Detecting Trailing Commas Before They Reach Production
Lint config files in CI with a JSON-strict parser. Any of these one-liners will fail the build on a trailing comma:
# jq — fastest, fails non-zero on parse error
jq empty config.json
# Python's stdlib (no install needed in most CI images)
python -m json.tool config.json > /dev/null
# Node — same parser the browser uses
node -e "JSON.parse(require('fs').readFileSync('config.json','utf8'))"
For TypeScript repos, set "trailingComma": "none" in Prettier's overrides for *.json files so the formatter doesn't insert one during a save.
When the Trailing Comma Is Not the Real Bug
If a payload comes from an API or a JSON-producing library and contains a trailing comma, the issue is upstream serialization, not the consumer. Fixing the comma locally hides a generator bug that will return on the next call — fix the producer instead. The same logic applies to log lines, message-queue payloads, and webhook bodies: a downstream parser should reject malformed JSON, not paper over it.
FAQ
Will JSON.parse ever accept a trailing comma?
No — strict mode is the standard and there's no flag to relax it. If you control both ends, use JSON5 for human-edited config and serialize to strict JSON for the wire.
Is JSON5 a safe alternative?
For human-edited configuration files (e.g., tsconfig.json, .vscode/settings.json use JSONC) — yes. For wire protocols, API payloads, message queues, or anything crossing a language boundary — no. Strict RFC 8259 JSON is what other languages' standard libraries actually parse.
Can the auto-repair tool remove only trailing commas?
Yes — paste the JSON into JSON Fix and it strips trailing commas along with the other common syntax fixes (single quotes, unquoted keys, comments, Python True/False/None) in one pass, in your browser. For the deeper explainer on why JSON forbids trailing commas in the first place, see Trailing comma in JSON: why { "a": 1, } throws an error.
See also
This guide is one stop in a larger repair workflow that covers trailing commas, unquoted keys, single quotes, and stringified-object errors. Open the hub for the full sequence.
Sources
- RFC 8259 — the JSON Data Interchange Format (IETF, the canonical JSON grammar)
- ECMA-404 — the JSON Data Interchange Syntax
- MDN —
JSON.parse(the strict parser that emits this error in JavaScript) - JSON5 — the human-edit-friendly superset that does allow trailing commas
Last reviewed June 2026.
JSON repair guides
Topic hubs
- JSON Parse Errors: Read the Message, Jump to the Fix
- Fix Invalid JSON: From 'What's Wrong' to a Clean File
- JSON Formatter, Validator, Viewer: Pick the Right Tool
- Repair LLM JSON Output: Handling Almost-JSON from AI
- Privacy: JSON Tools That Don't Leave Your Browser
- JSON Interop: YAML, CSV, XML, JWT, Schema
Specific guides
- How to Decode Base64 Strings (and JWT Payloads)
- URL Encoding: Percent-Encode Query Parameters and Paths
- Convert YAML to JSON (and Avoid Indentation Errors)
- Convert JSON to CSV: Flatten an Array of Objects
- Convert JSON to XML: Root Elements, Attributes, and Arrays
- Escape JSON as a String Literal (and Decode Double-Encoded JSON)
- Fix Single Quotes in JSON
- Fix Unquoted Keys in JSON
- Repair LLM JSON Output
- Fix JSON Parse Error: Expected Property Name
- JSON vs JS Object Literal: The Key Differences
- Validate JSON Before API Requests
- JSON Formatter vs JSON Repair
- Fix JSON Unexpected Token Errors
- JSON to JavaScript Object Converter