How to Fix Trailing Commas in JSON
Understand why trailing commas break RFC 8259 JSON parsing and discover how to automatically remove them with our free in-browser repair tool.
While JavaScript and TypeScript permit trailing commas in objects and arrays, the official RFC 8259 JSON grammar strictly forbids trailing commas, triggering immediate parser syntax errors.
Root Cause Analysis
Why trailing commas cause syntax errors in JSON
One of the most frequent syntax errors developers encounter when working with JSON configuration files and API payloads is the trailing comma (also known as a dangling comma or terminal comma). When copying and pasting properties in VS Code, Git merges, or JSON configs, leaving a trailing comma after the last property or array element causes JSON.parse() to throw an 'Unexpected token }' or 'Unexpected token ]' SyntaxError.
In ECMAScript 5+, JavaScript allows trailing commas to make multi-line git diffs cleaner. However, Douglas Crockford's official JSON specification (RFC 8259 and ECMA-404) was designed as a minimal, strict data interchange format. The formal grammar specifies that elements in an array or members in an object must be separated by commas, meaning no trailing comma can follow the final item before the closing bracket or brace. To check if your payload contains syntax violations, test it in our JSON Validator or format it with the JSON Formatter.
Manually searching through a 10,000-line configuration file to locate and delete rogue trailing commas is time-consuming and error-prone. Modern fault-tolerant parsers like JSONGlow can parse leniently, strip trailing commas automatically, and re-emit standardized, valid JSON in milliseconds without uploading your payload to external servers.
Whether you are fixing package.json files, tsconfig settings, AWS CloudFormation templates, or Kubernetes manifests, understanding the root cause and having an instant automated repair tool saves hours of debugging time. Ready to fix your broken files right now? Jump straight into our automated JSON Repair Tool or inspect related syntax guides like Unexpected Token in JSON.
Before & After Fix
Trailing Comma Remediation Example
See how invalid trailing commas in objects and arrays are automatically removed.
{
"service": "billing-api",
"replicas": 3,
"endpoints": [
"/healthz",
"/charges",
"/invoices", // Trailing comma in array
],
"timeout_ms": 3000, // Trailing comma in object
}{
"service": "billing-api",
"replicas": 3,
"endpoints": [
"/healthz",
"/charges",
"/invoices"
],
"timeout_ms": 3000
}Step-by-Step Fix
How to automatically remove trailing commas
Paste payload into JSON Repair
Paste your broken JSON payload with trailing commas directly into JSONGlow's JSON Repair workbench.
Instant AST-level remediation
The fault-tolerant parser identifies all dangling commas and removes them while preserving property order and data values.
Copy or download valid output
Copy the cleaned JSON back into your application or download it directly as a valid .json file.
Related Exceptions
Common SyntaxError messages caused by trailing commas
Unexpected token } in JSON at position X
Why it happens: A trailing comma precedes the closing curly brace in an object: { "a": 1, }.
// Broken: {"key": 1,}
// Fixed: {"key": 1}Unexpected token ] in JSON at position X
Why it happens: A trailing comma precedes the closing square bracket in an array: [1, 2, 3, ].
// Broken: [1, 2, 3,]
// Fixed: [1, 2, 3]Trailing commas in JSON with Comments (JSONC)
Why it happens: VS Code settings.json and tsconfig.json use JSONC (which allows trailing commas), but transferring these files to standard JSON tools causes syntax errors.
Key Insights
Best practices for clean JSON engineering
RFC 8259 Strictness
Understand why standard JSON parsers reject dangling commas by design.
One-Click Automated Fix
Use JSONGlow's JSON Repair tool to automatically strip trailing commas across multi-megabyte files.
100% Client-Side Privacy
All analysis and repairing take place locally in browser memory without server uploads.
Syntax Highlighting & Line Pointers
Locate exact line and column numbers of malformed tokens before and after remediation.
Frequently Asked Questions
Common questions answered.
Need more help? Our tools execute entirely in your browser without transmitting any payload to remote servers.
Why are trailing commas forbidden in standard JSON?+
The JSON format was designed in 2001 as a minimal, unambiguous data interchange standard. By strictly forbidding trailing commas, parser implementations across C, Java, Python, and Go remain simple, predictable, and fast without ambiguity over missing array elements.
Does JavaScript allow trailing commas?+
Yes. Modern JavaScript (ES5+) allows trailing commas in object literals and array declarations, but JSON.parse() enforces strict RFC 8259 grammar and will reject them.
How can I automatically fix trailing commas in my JSON?+
Paste your payload into JSONGlow's free JSON Repair tool. It parses the syntax leniently and automatically removes trailing commas, single quotes, and comments.
What is JSONC?+
JSONC stands for 'JSON with Comments'. Used by VS Code and TypeScript, it allows both single-line comments and trailing commas. However, it is not valid RFC 8259 JSON and cannot be parsed by standard JSON libraries without a preprocessor.
Can regex fix trailing commas reliably?+
Regex can handle simple cases (e.g. replacing ',\s*}' with '}'), but regex fails when commas appear inside string values. An AST-based tool like JSON Repair is required for reliable fixes.
Explore More Tools & Guides
The JSONGlow developer kit.
JSON Formatter
Format, beautify, indent, sort keys alphabetically, and inspect nested JSON structures.
Unexpected Token in JSON
Troubleshoot and fix 'Unexpected token in JSON' caused by single quotes, HTML error responses, or trailing commas.
JSON Validator
Live strict RFC 8259 syntax checker pointing to exact line and column coordinates of malformed tokens.