How to Format JSON for Faster Debugging
Minified API responses hide errors in plain sight. Learn a repeatable workflow—pretty-print, validate structure, decode JWTs, and test regex—using browser tools that keep payloads on your machine.
When an API returns a wall of minified JSON, debugging slows down before you find the actual bug. Keys blur together, missing commas hide in long strings, and nested arrays become impossible to scan. Pretty-printing is not cosmetic—it is how you turn opaque transport format into something your eyes can parse in seconds.
Copy the raw response from your browser network tab, terminal, or log file. Paste it into the JSON Formatter on Power Tools. Choose an indentation level—two spaces for compact logs, four spaces when you share snippets in code review. The formatter validates syntax as it renders. If a trailing comma or unquoted key breaks the document, you see the error location immediately instead of guessing which line failed.
Validation errors fall into a few predictable categories. A single missing quote often cascades into dozens of misleading messages; fix the first reported issue and re-format. Numbers stored as strings—"200" instead of 200—are valid JSON but may break strict comparisons in your application; highlight those while reading the indented output. Null versus absent keys matter in PATCH endpoints: formatted JSON makes it obvious when a field is explicitly null rather than missing.
Once the payload is readable, debug strategically rather than reading top to bottom. Identify the envelope: HTTP wrappers often place data under data, result, or items. Compare the shape you expect—array versus object—with what arrived. If pagination is involved, confirm page, total, and cursor fields before diving into individual records.
Authentication bugs frequently involve JWT access tokens. When an API returns 401 or 403, paste the bearer token—without the "Bearer " prefix if the decoder expects raw JWT—into the JWT Decoder tool. Inspect the exp claim first: expired tokens explain sudden failures that appear "random" because clocks crossed a boundary. Check iss and aud if your service validates issuer or audience. The payload section reveals roles, tenant IDs, and custom claims your backend might misread if types differ between services.
Never paste production tokens into public pastebins or chat screenshots with claims visible. Browser-based decoding on your own machine keeps the secret off third-party servers, but your screen and clipboard still matter. Clear the field after debugging on shared hardware.
String fields often contain escaped JSON or base64 blobs. After formatting the outer object, copy an inner string and format again. Some APIs double-encode errors: the message field holds a JSON string instead of an object. Pretty-printing each layer exposes the real validation message your UI should show users.
When logs include mixed text and JSON—common in webhook deliveries—use the Regex Tester to isolate the JSON block before formatting. A pattern such as \{[\s\S]*\} with careful anchoring can extract the object from surrounding headers. Test the regex against a saved sample log, then apply it consistently across similar entries. Combine regex extraction with the formatter so you do not manually delete timestamp prefixes line by line.
For regression work, minify formatted JSON back to a single line when you need to reproduce exact byte sequences in curl or Postman. The JSON Formatter supports minify mode for that round trip. Store both representations in your ticket: indented for human readers, minified for copy-paste reproduction steps.
Build a personal checklist for API incidents. Step one: format and fix syntax. Step two: map fields against your OpenAPI or TypeScript types. Step three: decode JWT if auth is involved. Step four: regex-extract embedded payloads from logs when necessary. Step five: document the smallest failing subset—remove unrelated branches until only the problematic key remains.
Teams benefit from agreeing on indentation and key ordering conventions even though JSON objects are technically unordered. Consistent formatting in pull requests reduces diff noise. When reviewing someone else's payload, ask them to paste formatted JSON rather than screenshots; text can be searched, images cannot.
Large arrays deserve special attention. Collapsing mentally at index zero is easy; bugs at index four hundred are not. After formatting, search for the specific ID or email from your bug report. If the formatter struggles with extremely large pasted input, split the array in your editor or request a paginated endpoint from the API owner.
Security-sensitive fields—passwords, refresh tokens, private keys—sometimes appear in accidental debug dumps. Redact before sharing formatted output in tickets, even internally. The formatter does not remove secrets for you.
With JSON Formatter for structure, JWT Decoder for token claims, and Regex Tester for pulling JSON out of messy logs, you turn frantic copy-paste sessions into a short, repeatable pipeline. The next time production returns 500 with a opaque body, you will spend minutes locating the offending field instead of hours fighting whitespace.