A single misplaced comma can bring down an entire API integration. JSON is the universal language of modern web data, but its syntax is unforgiving — one invalid character and everything stops parsing. This guide covers the five errors that cause 90% of JSON failures, how to debug them in seconds, and why validating sensitive payloads in a browser-based tool beats pasting them into random websites.
1. Why JSON Rules the Web
JSON (JavaScript Object Notation) won the data-format war because it hits a rare sweet spot: human-readable, machine-friendly and natively understood by every programming language. REST APIs speak it, config files use it, databases store it. But that simplicity hides strict rules — JSON is a data format, not a programming language, and it tolerates none of the conveniences developers enjoy in JavaScript itself.
2. The Five Errors Behind 90% of JSON Failures
- Trailing commas: JavaScript allows
[1, 2,]; JSON rejects it outright. The most common error by far, usually introduced when deleting the last item of a list. - Single quotes: JSON strings must use double quotes.
{'name': 'Ash'}is invalid;{"name": "Ash"}is correct. - Unquoted keys: Every object key must be a quoted string. JavaScript's shorthand
{name: "Ash"}fails in JSON. - Comments: JSON has no comment syntax. Any
//or/* */annotation breaks parsing — use a separate description field or JSONC-aware tooling instead. - Special values:
undefined,NaNandInfinitydo not exist in JSON. Usenull, strings, or numbers within valid range.
"JSON's strictness is a feature, not a flaw: a format that forgives nothing can be parsed identically by every system on earth."
3. Formatting: The Fastest Debugger You Own
Minified JSON — one endless line of brackets — is how APIs deliver data and how errors hide. Pretty-printing with consistent indentation instantly reveals structure: missing braces become visible, wrong nesting jumps out, and you can count depth at a glance. Professional workflow: paste the raw payload into a JSON formatter, fix what the structure exposes, then re-validate before shipping. Two clicks replace twenty minutes of squinting.
4. Validation Errors: Reading the Message Like a Pro
Error messages look cryptic but follow a pattern. "Unexpected token } in JSON at position 1,247" means the parser reached character 1,247 expecting data and found a closing brace — almost always a trailing comma just before it. "Unexpected end of JSON input" means something opened and never closed. The technique: jump to the reported position, then look backwards, because the parser reports where it gave up, not where you made the mistake. A validator with line numbers turns this hunt into a ten-second fix.
5. The Security Angle: Validate Before You Trust
JSON parsing has a darker side. Attackers craft malformed payloads to crash services or exploit parser differences between systems (a technique behind several API breaches). Defensively: validate input against a schema, reject unknown fields, and never eval() JSON — always use a real parser. And when debugging production payloads that contain user data, use a client-side validator like the OmniTools JSON Formatter, where the data never leaves your browser — pasting customer data into unknown online tools is a privacy incident waiting to happen (see our guide on client-side tools and data privacy).
6. Minify or Pretty-Print: Knowing When
Formatting is not just cosmetic — it is a workflow decision. Pretty-printed JSON with indentation is for humans: debugging, code review, documentation. Minified JSON is for machines: smaller payloads mean faster API responses and lower bandwidth. Ship minified in production, but always expand before debugging, and never edit minified JSON by hand — that is how trailing commas are born. A good formatter toggles between both views instantly, so the same payload serves both audiences.
7. Debug Your Next Payload in Seconds
Open the JSON Formatter & Validator, paste any payload, and get instant formatting plus precise error locations — completely offline-capable and private. Working with API tokens? The payload of a JWT is Base64URL-encoded JSON; inspect it safely with the JWT Decoder and the Base64 tool.
Frequently Asked Questions
Q: Why does my JSON fail with 'Unexpected token'?
The parser found a character it did not expect at the reported position — usually a trailing comma, single quotes or an unquoted key just before that point. Look backwards from the position to find the real mistake.
Q: Can JSON contain comments?
No. Standard JSON has no comment syntax. If you need comments, use JSONC (JSON with Comments) in tools that support it, or add a "_comment" field — but strip both before sending to a strict parser.
Q: What is the difference between null and undefined in JSON?
JSON only supports null. undefined is JavaScript-only; a property set to undefined is silently dropped when converting to JSON, which often causes 'missing field' bugs in APIs.
Q: Is it safe to paste API responses into online JSON tools?
Only if the tool processes data client-side. Responses may contain tokens or personal data. Browser-based validators like OmniTools parse everything locally, so nothing is transmitted anywhere.