JSON Formatting and Validation, Explained for Humans
JSON errors have a reputation for being cryptic — "Unexpected token at position 47" doesn't mean much at a glance. Once you know the handful of mistakes that cause 90% of JSON errors, they get a lot less scary.
The most common JSON mistakes
1. Trailing commas. JSON doesn't allow a comma after the last item in an object or array, unlike JavaScript object literals.
{
"name": "ToolHive",
"tools": ["pdf", "image"],
}
That trailing comma after the array is invalid JSON, even though it would be fine in a JavaScript file.
2. Single quotes instead of double quotes. JSON strictly requires double quotes for both keys and string values — single quotes will cause an immediate parse failure.
3. Missing commas between items. Easy to miss when editing by hand, especially in deeply nested structures.
4. Unescaped special characters. A literal quote or backslash inside a string needs to be escaped (\" or \\) or the parser will think the string ended early.
Reading a validation error
A message like "Unexpected token } in JSON at position 42" is actually telling you exactly where to look — position 42 is a character offset from the start of the file. A good validator converts that into a line and column number, which is far easier to act on than a raw character count.
Formatting vs. validating
These are related but different jobs:
- Validating checks whether the JSON is syntactically correct at all.
- Formatting takes valid JSON and reindents it consistently, which makes nested structures easy to scan visually.
If your JSON is invalid, formatting will fail too — you have to fix the syntax error first. That's actually a helpful signal: if a formatter throws an error, you know exactly where formatting stopped working.
A practical debugging habit
When you hit a JSON error in your own code, don't scan the whole file — paste it into a formatter/validator first. A precise line/column error turns a multi-minute hunt into a five-second fix.
JSON's strictness is a feature, not a flaw — it's exactly what makes it reliable to parse across every language and platform. Once the common pitfalls are familiar, the error messages stop being scary and start being genuinely useful.
Share this article
Related articles
URL Encoding, Explained Simply
What %20 actually means, and why some characters in a URL need to be encoded at all.
The Ultimate Guide to Free Online PDF Tools in 2026
A practical map of what free, browser-based PDF tools can actually do in 2026, and how to pick the right one without installing anything.
How to Compress a PDF Online for Free
Exactly how to compress a PDF online for free, what's happening behind the scenes, and how to tell a good compression result from a lazy one.