DEV Community

Rahib Ali
Rahib Ali

Posted on

Your JSON Formatter Says "Valid" — Here's What It's Not Telling You

Last month I spent forty minutes staring at a perfectly good API response. The endpoint returned 200. The payload looked right. My app still crashed on the third record, every single time.

I pasted the response into a formatter. Big green checkmark: valid JSON. I pasted it again, slower, as if that would help. Still valid. The bug was not in the syntax at all, and that is exactly the problem with how most of us use formatters.

A "valid" verdict answers one narrow question: does this text follow the grammar of JSON? It says nothing about whether the data means what you think it means. The gap between valid and correct is where the nastiest production bugs live.

Valid is a low bar

JSON has a tiny grammar. Objects, arrays, strings, numbers, true, false, null. That is the whole language, and the formal definition fits on a single page at json.org.

A formatter that only checks grammar will happily bless a payload that loses data, misleads your code, or behaves differently in every language that touches it. The spec itself, RFC 8259, warns that object member names SHOULD be unique — and then admits that parsers disagree about what to do when they are not.

So the green checkmark is the beginning of the investigation, not the end of it. Here are the four traps I now check for every time a payload misbehaves, in the order I check them.

1. Duplicate keys silently eat your data

This is the one that bit me last month. The response contained something like this:

{
  "user_id": 4821,
  "name": "Aisha Khan",
  "plan": "starter",
  "plan": "pro"
}
Enter fullscreen mode Exit fullscreen mode

Two plan keys. Perfectly valid JSON grammar. Most parsers keep the last value and throw the first one away without a word. Some keep the first. A few raise an error. Your formatter probably did not even blink.

In my case, the API had a merge bug upstream. The first plan came from the billing service, the second from a stale cache. My app read "pro", the billing page read "starter", and the customer got charged for a plan the dashboard said she did not have.

A good formatter flags duplicate keys loudly, because the JSON specification says names SHOULD be unique and duplicate names make behavior unpredictable. If yours does not, you are flying blind on the most common silent-data-loss bug in JSON.

2. Trailing commas: valid in your editor, invalid in JSON

If you write JavaScript all day, this one will get you eventually:

{
  "name": "Rahib",
  "role": "developer",
}
Enter fullscreen mode Exit fullscreen mode

That trailing comma after "developer" is fine in JavaScript and Python. It is a syntax error in JSON. Strictly speaking, your formatter should reject it — and a strict one will.

The confusion runs the other way too. Some lenient tools quietly accept trailing commas, so you ship a config file that works in your editor and fails in production, where the real parser is strict. I have seen this take down a deploy: the config validated in the developer's tool, then the server's JSON parser rejected it at startup.

When a formatter accepts something, ask whether it is accepting real JSON or being polite. Politeness is not a feature here. You want the tool that fails exactly the way your production parser fails.

3. Numbers lose precision without warning

This is the trap that costs real money, and it is the one almost nobody checks:

{ "order_id": 9007199254740993 }
Enter fullscreen mode Exit fullscreen mode

That number is valid JSON. It is also larger than 2^53, which means JavaScript cannot represent it exactly. Parse it with JSON.parse and you get 9007199254740992. One digit off. Your order lookup now points at a different order — or at none at all.

The same hazard hits any language with double-precision floats, which is most of them. The JSON spec places no limit on number precision, but your runtime does, and the two limits are not the same.

APIs that return large IDs as numbers are a known footgun. The safe pattern is to send IDs as strings. But you cannot fix the API from your side of the screen. What you can do is notice: a formatter that shows you the parsed value next to the raw text makes the precision loss visible before it reaches your database.

If you work with IDs, timestamps in milliseconds, or money in minor units, check what your formatter does with a 16-digit number. If it silently rounds, it is hiding exactly the bug you are trying to find.

4. Strings that look like numbers (and booleans that aren't)

JSON has exactly six value types, and the boundaries between them are where bugs breed:

{
  "is_active": "true",
  "retry_count": "3",
  "price": "19.99"
}
Enter fullscreen mode Exit fullscreen mode

Every value here is a string. "true" is not the boolean true. "3" is not the number 3. In a loosely typed language, "3" + 1 gives you "31", not 4. In a strictly typed one, it gives you a type error at 2 a.m.

This usually happens when a backend serializes everything as strings — a database driver returning text columns, or a CSV import that never converted types. The JSON is valid. The types are wrong. And the failure shows up three services downstream, far from the cause.

A formatter that shows types explicitly — string vs number vs boolean, ideally with colour — turns this from a guessing game into a glance. When I am debugging a payload now, the first thing I look at is not the values. It is the types.

What a good formatter actually tells you

After a few rounds of this, my checklist for a JSON tool changed completely. When you paste a payload into an online JSON formatter, you are really asking it three questions at once: is the grammar right, are the types what I expect, and is anything being silently lost? Syntax validation is table stakes. What I actually need is a tool that:

  • Flags duplicate keys instead of silently accepting them.
  • Rejects trailing commas the way a strict parser would.
  • Shows parsed numbers next to raw text so precision loss is visible.
  • Makes types obvious at a glance, with strings, numbers, and booleans visually distinct.
  • Formats and minifies without ever changing the data.

That is a short list, and most tools fail at least one item on it. The one I reach for now is the free json formatter from FrostRank — it validates strictly, flags duplicate keys, and shows the parsed structure with types, which is exactly the set of checks this article is about.

The point is not which tool you use. The point is knowing what to demand from it. A formatter that only says "valid" is a spell-checker that never checks meaning.

A debugging checklist for the next bad payload

The next time a payload looks right and behaves wrong, work through these in order before you blame the API:

  1. Check for duplicate keys. Search the raw text for repeated member names inside the same object.
  2. Check the types. Is anything that should be a number or boolean actually a string?
  3. Check large numbers. Any integer above 9,007,199,254,740,991 may have lost precision in transit.
  4. Check for trailing commas and comments. Both are common in hand-written config and both are invalid JSON.
  5. Parse it in the same language your app uses. A payload that is valid in Python and valid in JavaScript can still behave differently in each.

Most "the API is broken" bugs I have investigated turned out to be one of these five. The API was fine. The JSON was valid. And the data was wrong anyway.

That is the lesson the green checkmark never teaches: valid JSON is a promise about grammar, not about meaning. The sooner you stop treating the two as the same thing, the sooner the forty-minute mysteries become five-minute fixes.

Further reading

If you have your own JSON horror story — a duplicate key, a rounded ID, a string that should have been a number — I would genuinely like to hear it. The best debugging checklists are built from other people's production incidents, and this one is still growing.

Top comments (0)