Skip to content
ForgePlug — Logo
All resources
Developer Guides

How to Format JSON When Debugging API Responses

Raw API responses arrive as one long unreadable line. Here's how to format them, what the common errors mean, and when formatting alone won't save you.

5 min read · By ForgePlug Team · Published August 15, 2026

The first time you inspect a real API response in a network tab or a terminal, it usually looks like a single 2,000-character line: objects nested inside objects, no line breaks, no indentation. That's not a bug in your code — it's minified JSON, which servers send to save bandwidth. Before you can read the data, you need to format it: expand it into indented lines so each object, key, and value is visible.

What formatting actually does

Formatting (also called beautifying or pretty-printing) adds whitespace only — it changes nothing about the data itself. A formatter parses the JSON into a structure, then re-serializes it with indentation. Because it's a pure visual transformation, you can format and minify back and forth indefinitely without losing information. The one thing a formatter cannot do is fix invalid JSON: if the payload has a syntax error, there is nothing to parse, and formatting will only tell you where the error is.

A real example

Here is what a typical API response looks like straight off the wire:

  • Raw: {"user":{"id":42,"name":"Ada","roles":["admin","billing"]},"meta":{"page":1,"total":137}}
  • Formatted: the same data with each key on its own line, nested objects indented, and arrays split item-by-item so you can see at a glance that user.roles contains two values.

Once formatted, the structure is readable in seconds: the top-level keys, the shape of nested objects, and where arrays begin and end. That's usually enough to spot a missing field, an unexpected null, or a response wrapped one level deeper than your code expects.

The errors you'll actually meet

  • Trailing commas — JSON forbids a comma after the last item in an object or array: {"a":1,} is invalid, even though many JavaScript tools tolerate it.
  • Single quotes — JSON requires double quotes for keys and strings. {'name': 'Ada'} is valid JavaScript but invalid JSON.
  • Unquoted keys — {name: "Ada"} works in JS, not in JSON.
  • Trailing garbage — a stray comma, bracket, or second document after the closing brace makes the whole payload invalid.
  • NaN or undefined values — these aren't representable in JSON and usually indicate a serialization bug on the server.

Formatting is not validation

A formatter that prints your JSON back out has parsed it successfully — that's a good sign. But it does not verify that fields are the right type, that required keys exist, or that values are in range. Use a validator or your own assertions for semantic checks.

The debugging workflow

  1. Copy the raw response body from the network tab, curl output, or logs.
  2. Paste it into a JSON formatter — if it prints, your syntax is valid and you can read the structure.
  3. If it refuses to format, read the error location and fix the reported character (usually a missing quote, extra comma, or truncation).
  4. Compare two versions of a response with a diff tool when the payload changed between requests.

Format that response now

Paste any raw API response into ForgePlug's JSON Formatter & Validator — it runs entirely in your browser, so the payload never leaves your machine.

Open JSON Formatter & Validator

More Developer Guides