Trailing commas in JSON: why they break parsing (and fixes)
JavaScript allows trailing commas in many cases. JSON does not. That mismatch causes fast, confusing failures.
What is a trailing comma?
A trailing comma is a comma right before a closing } or ]. It’s common in
JavaScript objects, but strict JSON forbids it. Example patterns:
{"a": 1,} or [1, 2,].
How to spot it quickly
- Search for
,}and,]patterns. - Check the last property in objects and the last item in arrays.
- If the error includes “position”, inspect a few characters before that index.
Fix strategy (fast, safe)
- Remove the comma before the closing bracket.
- Re-validate to catch the next syntax issue (if any).
- Only then check “structure” (array vs object) for converters.
Trust note: All processing happens locally in your browser. Files are never uploaded.
Practical checklist (fast)
If you’re stuck, use this quick checklist to narrow the problem before you try “random fixes”. Start by validating the input format (syntax first), then confirm shape expectations (array vs object, headers vs rows). Convert a small sample, inspect the output, and only then export the full result.
- Validate: confirm the input is strict JSON/XML/CSV (no stray characters).
- Confirm shape: arrays vs objects; headers vs row lengths; repeated tags vs arrays.
- Test a sample: first 20–50 rows/items are enough to detect parsing issues.
- Export: copy/download the output and re-check it in the consumer (script/spreadsheet/API).
This workflow is privacy-first by design: All processing happens locally in your browser. Files are never uploaded.
Practical checklist (fast)
If you’re stuck, use this quick checklist to narrow the problem before you try “random fixes”. Start by validating the input format (syntax first), then confirm shape expectations (array vs object, headers vs rows). Convert a small sample, inspect the output, and only then export the full result.
- Validate: confirm the input is strict JSON/XML/CSV (no stray characters).
- Confirm shape: arrays vs objects; headers vs row lengths; repeated tags vs arrays.
- Test a sample: first 20–50 rows/items are enough to detect parsing issues.
- Export: copy/download the output and re-check it in the consumer (script/spreadsheet/API).
This workflow is privacy-first by design: All processing happens locally in your browser. Files are never uploaded.
FAQ
Why did this work in my editor but not in JSON.parse? Many editors accept “JSON with comments/trailing commas” as a convenience.
Can a converter fix this automatically? Some do, but it’s safer to fix input and keep strict JSON, especially for APIs.
Local verification snippet
Run a quick local check before export/convert:
const text = input.trim();
const value = JSON.parse(text);
console.log(Array.isArray(value) ? 'array' : typeof value);