Tutorial · 5 min read

How to Fix JSON Trailing Commas and Single Quotes

Trailing commas and single quotes are the #1 reason JSON parsers fail. An auto-fix trailing commas with JSON Repair tool catches and fixes both instantly — no manual scanning required.

1. Trailing Commas: The Most Common JSON Mistake

A trailing comma is a comma after the last element in an object or array. It's valid in JavaScript and many other languages, but the JSON specification (RFC 7159) explicitly forbids it:

// ❌ Invalid JSON — trailing comma after "age"
{
  "name": "Alice",
  "age": 30,   // ← this comma breaks the parser
}

// ❌ Also invalid — trailing comma in array
["red", "green", "blue",]

// ✅ Valid JSON
{
  "name": "Alice",
  "age": 30
}

// ✅ Valid array
["red", "green", "blue"]

The trailing comma is a classic copy-paste artifact. You add a new field, and the comma you inserted at the end of the previous line accidentally remains after the last item. The parser refuses to accept it.

To spot trailing commas manually, look for commas on the line just before a closing brace } or bracket ]. Syntax-highlighting editors often flag them in red.

2. Single Quotes: Where They Creep In

JSON strings must use double quotes ("). Single quotes (') are not valid, even though they work in JavaScript, Python, and many other languages:

// ❌ Invalid JSON — single quotes
{ 'name': 'Alice', 'role': 'Engineer' }

// ❌ Also invalid — mixed quotes
{ "name": 'Alice' }

// ✅ Valid JSON
{ "name": "Alice", "role": "Engineer" }

Single quotes commonly appear when developers hand-write JSON (because typing Shift+' is easier than Shift+"), or when JSON is copied from Python repr() output or JavaScript template literals that mix quotes.

Key names also require double quotes. { name: "Alice" } is invalid — it must be { "name": "Alice" }.

3. Other Syntax Errors a Repair Tool Handles

Beyond trailing commas and single quotes, a good JSON repair tool can fix several other common issues:

Error Example Repair Action
Missing quotes on keys {name: "Alice"} Add double quotes
Extra commas in objects {,,"a":1} Remove extra commas
Missing closing bracket {"a":[1,2 Append ]}
Unescaped control chars "line1\nline2" Escape properly

The JSON Repair tool handles all these cases automatically, outputting valid JSON ready for any parser.

4. Manual Fix vs Automated Repair

You have two approaches to fix these errors:

// Regex to find trailing commas in VS Code:
// Search: ,(\s*[}\]])
// Replace: $1
// (Use regex mode)

For one-off fixes, manual search-and-replace is fine. For repeated work — especially from an API that intermittently sends malformed JSON — automated repair saves hours.

5. Always Validate After Repair

Even the best repair tool can make mistakes with ambiguous input. Always validate the output:

  1. Run the broken JSON through the repair tool
  2. Paste the repaired output into a JSON validator
  3. Confirm the validator says "Valid JSON" before deploying or using the data
// After repair — should validate successfully
{
  "name": "Alice",
  "greeting": "It's a nice day",
  "items": ["a", "b", "c"]
}

Note: the repair tool correctly handles apostrophes inside values (It's) — it knows that the single quote in It's is not a string delimiter.

For an extra layer of safety, keep the JSON Editor open in a second tab — it validates in real-time as you edit, so you can spot any remaining issues immediately.

Try the JSON Repair Tool

Paste broken JSON — trailing commas, single quotes, missing brackets — and get clean, valid JSON instantly. 100% browser-based, no data sent to servers.

Fix JSON Now →

Best Practices to Avoid Trailing Commas and Single Quotes

Frequently Asked Questions

Why does JavaScript allow trailing commas but JSON doesn't?

JavaScript's object literal syntax evolved to allow trailing commas for convenience — it makes adding new items cleaner in diffs. JSON was designed as a strict, language-independent data interchange format (RFC 7159) and deliberately excludes trailing commas for maximum portability between parsers.

Does JSON support single quotes for strings?

No. The JSON specification (RFC 7159) requires strings to be enclosed in double quotes. Single-quoted strings are valid in JavaScript but not in strict JSON. Most JSON parsers will reject single-quoted strings as syntax errors.

Will a JSON repair tool remove comments from my file?

Most repair tools strip non-standard content like comments (// or /* */) because they are not valid JSON. If you need to preserve comments, use a JSON5-compatible parser instead, or keep a backup of the original file before repairing.

Can I batch-repair multiple JSON files at once?

Some online tools support batch upload and repair. For local files, you can use a command-line JSON repair module like 'jsonrepair' (npm) in a bash loop to process directories.

Is it safe to paste sensitive JSON into an online repair tool?

Yes — as long as the tool processes everything in the browser. Client-side tools never send your data to a server. Always check for a claim like '100% client-side' or 'your data never leaves your browser' before pasting sensitive information.

Looking for more guides? See the full JSONXX How To index.