Last week I spent 4 hours debugging what turned out to be a single trailing comma in a JSON config file.
4 hours. For a comma.
If you work with APIs, databases, or any modern web stack, you've probably had a version of this experience. JSON is unforgiving — one wrong character breaks everything, and the error messages are often vague.
Here's what I now do differently.
What Happened
I was setting up an integration with a third-party API. The config file was about 200 lines of JSON. Every time I sent it, the API returned:
{ "error": "Invalid JSON in request body" }
No line number. No character position. Just "invalid."
I reviewed the file visually. Nothing looked wrong. I compared it to the API docs. Structure was right. I checked the character encoding — UTF-8, fine.
After 3 hours I gave up and pasted it into our JSON formatter. The tool processed it in 0.2 seconds and returned:
Syntax error at line 47:
Trailing comma at the end of object
Line 47. The last line of a nested object. I'd left a comma after the final key-value pair.
Fixed in 30 seconds. But the 4 hours were gone.
Why JSON Errors Are So Painful
JSON has strict rules:
- No trailing commas
- No comments (unlike JavaScript)
- Double quotes only (not single quotes)
- Keys must be quoted strings
- No unquoted values except: true, false, null, numbers
If you break any of these, the entire file fails. Unlike JavaScript, which is forgiving, JSON has no tolerance for "close enough."
And error messages from JSON parsers are notoriously unhelpful. "Unexpected token" tells you nothing about where or why.
My New Workflow for JSON
Every time I work with JSON now, I do this first:
- Paste the JSON into JSON formatter
- Click "Validate"
- If there's an error, it tells me the exact line and character
- Fix it
- Click "Format" to make sure it's readable before sending
Total time: 30 seconds. Saves hours of manual searching.
The 5 Most Common JSON Errors
From years of working with APIs, here are the ones I see most:
1. Trailing comma
{
"name": "John",
"age": 30,
}
Invalid. The comma after "30" is a syntax error.
Fix: Remove the comma.
2. Single quotes
{ 'name': 'John' }
Invalid. JSON requires double quotes.
Fix: Change to {"name": "John"}.
3. Unquoted keys
{ name: "John" }
Invalid. Even though JavaScript allows it, JSON doesn't.
Fix: Quote the key: {"name": "John"}.
4. Comments
{
// this is my config
"port": 8080
}
Invalid. JSON has no comment syntax.
Fix: Remove comments. If you need them, use JSON5 or YAML.
5. Smart quotes
{ "name": "John" }
This one is subtle. That's a curly quote (U+201C and U+201D) instead of straight quotes. Happens when you copy from Word or Google Docs.
Fix: Retype the quotes or paste into a plain-text editor first.
Our JSON formatter catches all 5 with specific error messages.
When You Should Minify JSON
If you're sending JSON over an API, minify it:
Before (formatted, 240 bytes):
{
"name": "John",
"age": 30
}
After (minified, 27 bytes):
{"name":"John","age":30}
For a small config, it doesn't matter. But if you're sending thousands of records, minification cuts payload size by 40-60%.
Use our JSON formatter — it has a "Minify" button. One click, no data loss.
When You Should NOT Minify
Minified JSON is unreadable. If you need to edit it later, don't minify:
- Config files you edit manually
- Data you need to review
- Examples in documentation
Minify only for transmission, not storage.
How I Handle Large JSON Files Now
For anything over 100 lines, I never edit by hand in a text editor. I:
- Paste into JSON formatter
- Click "Format" to make sure structure is clean
- Edit in a proper JSON editor (VS Code with JSON extensions)
- Validate again before sending
The formatting step matters because bad indentation hides errors. When everything is properly indented, you can visually spot missing brackets.
The Tool That Would Have Saved Me 4 Hours
If you work with JSON — even occasionally — bookmark our JSON formatter. It does:
- Format (pretty-print)
- Minify
- Validate (with line numbers)
- Escape / unescape
All in your browser, no upload, no sign-up.
Those 4 hours I lost taught me a lesson: 30 seconds of validation beats 4 hours of manual debugging. Every time.