JSON Formatter 101: Fix Trailing Commas, Quotes, Encoding & More
Broken JSON is usually a tiny typo. This guide shows quick, copy-paste fixes for trailing commas, quotes, escaping, encoding, and number pitfalls—plus a reliable workflow using our JSON Formatter.

Quick start: fix invalid JSON in 60 seconds
- Replace all single quotes with double quotes for keys and strings.
- Remove any trailing commas before
}
or]
. - Escape special characters inside strings:
"
→\"
, newline →\n
. - Ensure the document is UTF-8 (no BOM).
- Paste into the JSON Formatter, click Validate, then Pretty-print.
Common JSON errors (with examples)
1) Trailing commas
// ❌ Invalid
{
"name": "Ava",
"roles": ["admin","editor",],
}
// ✅ Valid
{
"name": "Ava",
"roles": ["admin","editor"]
}
2) Single quotes instead of double quotes
// ❌ Invalid
{'name': 'Ava', 'active': true}
// ✅ Valid
{"name": "Ava", "active": true}
3) Unescaped quotes / control characters
// ❌ Invalid
{"note": "He said "hello""}
// ✅ Valid
{"note": "He said \"hello\""}
4) Comments (JSON doesn’t allow them)
// ❌ Invalid
{
// price in USD
"price": 10
}
// ✅ Valid (move notes into a field)
{
"price": 10,
"_note": "price in USD"
}
5) Duplicate keys (last one wins, unpredictable)
// ❌ Avoid
{"id": 1, "id": 2}
// ✅ Use unique keys
{"id": 2}
6) NaN / Infinity (not in JSON spec)
// ❌ Invalid
{"value": NaN, "limit": Infinity}
// ✅ Valid
{"value": null, "limit": 1e309}
7) Leading zeros in numbers
// ❌ Invalid in many parsers
{"zip": 0123}
// ✅ Quote if it must preserve zeros
{"zip": "0123"}
8) Top-level type surprises
Most parsers accept any JSON value, but some tools expect an object or array at the top. If in doubt, wrap it:
// Safer top-level
{"data": true}
Escaping & encoding
Escape sequences to know
\"
double quote\\
backslash\n
newline,\t
tab\uXXXX
unicode code point (e.g.,\u00A9
)
Fix encoding issues
- Ensure your file is saved as UTF-8 (no BOM).
- Replace “smart quotes” with straight quotes before parsing.
- Normalize line endings (LF) if you copy from Windows editors.
Numbers & precision (don’t lose money)
- JavaScript safely represents integers up to
9,007,199,254,740,991
(Number.MAX_SAFE_INTEGER
). - For big IDs, account numbers, or precise currency, send as strings (e.g.,
"amount":"12.34"
). - Avoid commas in numbers (
1,234
)—use1234
and format later in the UI.
Large files without headaches
- Stream or chunk when possible instead of loading entire files in memory.
- Use NDJSON (newline-delimited JSON) for logs: one JSON object per line.
- Validate early—pretty-print as you build so errors surface near their source.
Safe workflow with the JSON Formatter
- Paste your payload into JSON Formatter.
- Click Validate to get the exact line/column of syntax issues.
- Use Pretty-print for readable indentation and to spot structure mistakes.
- Toggle minify for production or API requests.
- Copy result and test in your app or cURL before shipping.
Tip: keep schema examples in version control so your team aligns on shape and types.
Troubleshooting
“Unexpected token” near a bracket: look for a missing comma between properties or a trailing comma before }
/]
.
Works in one tool but not another: the lenient tool might allow comments or single quotes—stick to strict JSON.
Weird characters (�): your file isn’t UTF-8—resave as UTF-8 without BOM.
Large integers changing value: serialize as strings and parse as BigInt/decimal in your app.
Previous
QR Codes that People Actually Scan: Size, Color, Logo
Next
CSV ⇄ JSON: Encoding, Delimiters, and Headers (No Headaches)