DEV Community

Sahil Bedi
Sahil Bedi

Posted on

7 JSON Formatting Mistakes Every Developer Has Made

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
Enter fullscreen mode Exit fullscreen mode

Or:

Invalid JSON
Enter fullscreen mode Exit fullscreen mode

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,
}
Enter fullscreen mode Exit fullscreen mode

✅ Correct

{
  "name": "John",
  "age": 30
}
Enter fullscreen mode Exit fullscreen mode

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"
}
Enter fullscreen mode Exit fullscreen mode

✅ Correct

{
  "name": "John"
}
Enter fullscreen mode Exit fullscreen mode

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'
}
Enter fullscreen mode Exit fullscreen mode

✅ Correct

{
  "city": "London"
}
Enter fullscreen mode Exit fullscreen mode

JSON only supports double quotes.


4. Forgetting to Escape Special Characters

Strings containing quotation marks must escape them properly.

❌ Invalid

{
  "message": "He said "Hello""
}
Enter fullscreen mode Exit fullscreen mode

✅ Correct

{
  "message": "He said \"Hello\""
}
Enter fullscreen mode Exit fullscreen mode

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"
}
Enter fullscreen mode Exit fullscreen mode

This stores a string, not a boolean.

Correct version:

{
  "isActive": true
}
Enter fullscreen mode Exit fullscreen mode

Likewise:

{
  "count": "25"
}
Enter fullscreen mode Exit fullscreen mode

is different from

{
  "count": 25
}
Enter fullscreen mode Exit fullscreen mode

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"
    ,
Enter fullscreen mode Exit fullscreen mode

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"}}
Enter fullscreen mode Exit fullscreen mode

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)