We've all been there.
You copy an API response into your editor, make a small change, send the request again...
…and suddenly you're staring at:
Unexpected token } in JSON at position 128
Or:
Invalid JSON
After several minutes of debugging, you realize it was a missing comma or an extra quote.
JSON is one of the most common data formats in modern software development, but even experienced developers make formatting mistakes. The good news is that most of these issues are easy to spot once you know what to look for.
Here are seven of the most common JSON formatting mistakes I've encountered over the years.
1. Trailing Commas
One of the most frequent mistakes.
❌ Invalid
{
"name": "John",
"age": 30,
}
✅ Correct
{
"name": "John",
"age": 30
}
Unlike JavaScript objects, JSON does not allow trailing commas.
2. Missing Double Quotes Around Property Names
JSON requires every property name to be enclosed in double quotes.
❌ Invalid
{
name: "John"
}
✅ Correct
{
"name": "John"
}
Many developers accidentally write JavaScript object syntax instead of valid JSON.
3. Using Single Quotes Instead of Double Quotes
Another common mistake is using single quotes for string values.
❌ Invalid
{
"city": 'London'
}
✅ Correct
{
"city": "London"
}
JSON only supports double quotes.
4. Forgetting to Escape Special Characters
Strings containing quotation marks must escape them properly.
❌ Invalid
{
"message": "He said "Hello""
}
✅ Correct
{
"message": "He said \"Hello\""
}
The same applies to backslashes and certain control characters.
5. Incorrect Data Types
Everything might look correct while still producing incorrect data.
For example:
{
"isActive": "true"
}
This stores a string, not a boolean.
Correct version:
{
"isActive": true
}
Likewise:
{
"count": "25"
}
is different from
{
"count": 25
}
Choosing the correct data type prevents many downstream bugs.
6. Mismatched Braces or Brackets
Large JSON files become difficult to read.
A missing brace can invalidate the entire document.
For example:
{
"users": [
{
"id": 1,
"name": "Alice"
,
Formatting your JSON immediately makes these issues much easier to identify.
7. Trying to Read Minified JSON
Many APIs return compressed JSON like this:
{"id":1,"name":"John","roles":["Admin","Editor"],"settings":{"theme":"dark","language":"en"}}
Technically it's valid.
Practically, it's painful to debug.
Formatting it into an indented structure makes nested objects and arrays much easier to understand.
My Workflow
Whenever I'm debugging an API response, I usually follow the same process:
- Validate the JSON first.
- Format it for readability.
- Check nested objects.
- Verify data types.
- Look for missing commas or braces.
It only takes a few seconds and saves a surprising amount of debugging time.
A Small Tool That Helps
While building ToolNudge, I found myself repeatedly pasting JSON into editors just to check whether it was valid or to make it readable.
To simplify that workflow, I built a browser-based JSON Formatter & Validator.
It lets you:
- Format JSON instantly
- Validate syntax
- Detect formatting errors
- Minify JSON when needed
Everything runs directly in the browser, so your data never leaves your machine.
👉 https://toolnudge.com/json-formatter-validator
Final Thoughts
JSON isn't complicated, but small formatting mistakes can interrupt your flow and waste valuable debugging time.
A quick validation step before sending requests or committing configuration files can prevent many of the errors developers encounter every day.
What JSON mistake has wasted the most time for you?
I'd love to hear your experiences in the comments.
Tags
webdev json javascript productivity
Top comments (0)