The Problem
You're debugging an API response, and it looks like this:
{"status":"ok","data":{"items":[{"id":1,"name":"Widget","metadata":{"created":"2024-01-15T08:30:00Z","tags":["electronics","sale"],"pricing":{"usd":29.99,"eur":26.50}},"stock":42},{"id":2,"name":"Gadget","metadata":{"created":"2024-02-20T14:15:00Z","tags":["office"],"pricing":{"usd":15.00,"eur":13.25}},"stock":0}]},"pagination":{"page":1,"total":2}}
Good luck finding the nested pricing field. Now imagine this is 500 lines long.
Here are three tricks that save me hours every week when working with JSON.
1. Pretty-Print First, Debug Later
Before you even look at a JSON blob, format it. Most terminal users reach for python -m json.tool, but that only handles valid JSON. If there's a trailing comma or a missing quote, it fails with an unhelpful error.
A good JSON formatter shows you where the syntax error is, not just that it exists. Missing closing bracket on line 47? An inline formatter catches that instantly.
My workflow: paste raw JSON → identify structural issues → read the formatted output → debug the logic. The formatting step takes 2 seconds but saves 10 minutes of squinting at minified blobs.
2. Collapse Deeply Nested Structures
When an API response goes 4+ levels deep, the tree view is your best friend. Instead of scrolling through 200 lines, collapse everything and expand only the branch you're interested in.
Most dev tools don't do this well, but a dedicated formatter with tree view lets you drill down to response.data.items[3].metadata.pricing.usd in two clicks — without losing context of where you are in the structure.
3. Validate JSON Before It Reaches Production
I've shipped config files with trailing commas more times than I'd like to admit. JSON is stricter than JavaScript — no trailing commas, no single quotes, no comments.
-
Trailing comma trap:
{"key": "value",}works in JS but failsJSON.parse() -
Single-quote habit: Switching between JS and JSON makes
{'key': 'value'}feel right — it's not -
Empty values:
{"key": }or{"key": NaN}— JSON doesn't supportundefinedorNaN
A validator that pinpoints the exact character position of the error catches these before your CI pipeline does.
I use CodeToolbox's JSON Formatter for all three — it handles formatting, tree view, and validation in one page, all client-side (nothing sent to a server).
What's your go-to JSON debugging workflow?