How to Fix the JSON Trailing Comma Error

JSON does not allow trailing commas. Remove the comma before ] or }. This is the most common JSON syntax error. Unlike JavaScript, Python, and other languages that allow trailing commas, the JSON specification (RFC 8259) strictly forbids them.

Before and After

// INVALID — trailing comma after "b": 2
{
  "a": 1,
  "b": 2,   <-- remove this comma
}

// VALID
{
  "a": 1,
  "b": 2
}

// INVALID — trailing comma in array
[1, 2, 3,]   <-- remove this comma

// VALID
[1, 2, 3]

How to Catch Trailing Commas

Regex to Remove Trailing Commas

// JavaScript — quick fix (use with caution)
jsonStr = jsonStr.replace(/,\s*([}\]])/g, '$1');

Warning: this regex can break JSON strings that contain ,} or ,] as literal text. Always validate after applying.

Try It Yourself

Use our JSON Validator to find and fix errors, or our JSON Formatter to clean up your JSON.

Frequently Asked Questions

Which formats allow trailing commas?

JavaScript (ES5+), JSON5, JSONC, Python, Rust, and Go all allow trailing commas. Standard JSON does not.

Why doesn't JSON allow trailing commas?

Douglas Crockford, who formalized JSON, chose simplicity: the grammar is smaller and parsers are simpler without optional trailing commas. This also avoids ambiguity with empty trailing elements.

Built by Michael Lip. 100% client-side — no data leaves your browser.