QuietJSON
SyntaxError: Unexpected Token

Fix: Trailing Comma in JSON

You added a comma after the final property in an object or array, and JSON.parse() crashed with a SyntaxError pointing to } or ].

SyntaxError: Unexpected token '}', "..."name": "Alice",}" is not valid JSON
(or: Expected double-quoted property name)

Why Does JSON Forbid Trailing Commas?

In modern JavaScript, TypeScript, Python, and Rust, trailing commas are recommended best practice because they make git diffs cleaner when adding new properties.

However, JSON is not JavaScript. In RFC 8259 Section 4, an object is strictly defined as zero or more name/value pairs separated by commas. A comma tells the parser: "Expect another property immediately after this." When the parser finds a closing bracket (]) or closing brace (}) instead, it fails with a SyntaxError.

Examples: Broken vs. Fixed

Invalid (Trailing Commas):
{
  "id": 1,
  "tags": ["dev", "ui",],
  "active": true,
}
Valid JSON (RFC 8259):
{
  "id": 1,
  "tags": ["dev", "ui"],
  "active": true
}

Why LLMs (ChatGPT, Claude) Output Trailing Commas

Large language models generate tokens sequentially. When finishing an object item, the model's training on millions of JavaScript and Python code files strongly predicts a trailing comma before outputting the closing brace. If you are building AI agents or processing LLM outputs, you should always run an auto-repair step to sanitize trailing commas.

Frequently Asked Questions

Why does JSON forbid trailing commas when JavaScript allows them?

Douglas Crockford designed JSON in 2001 as a strict, universal data interchange subset of ECMAScript 3. In ES3 (and old browsers like Internet Explorer 6/7), trailing commas caused runtime syntax errors or created extra undefined array elements. To ensure compatibility across every programming language, RFC 8259 explicitly specifies that commas must separate items and cannot follow the last item.

How do I fix trailing comma errors automatically?

Paste your JSON into the QuietJSON Repair tool (quietjson.com/json-repair/). It safely removes all trailing commas before closing braces and brackets in one click.

Does JSON5 or JSONC allow trailing commas?

Yes. Extensions like JSON5 and JSONC (used in VS Code configuration files) explicitly permit trailing commas and comments. However, standard API endpoints and native JSON.parse() require strict RFC 8259 compliance.

Auto-remove trailing commas instantly

QuietJSON Repair cleans up trailing commas in objects and arrays with a single click.

Fix Trailing Commas →