Why API Responses Look Like a Wall of Text
You call an API, copy the response, and paste it into your editor — and get this:
{"users":[{"id":1,"name":"Lena","roles":["admin","editor"]},{"id":2,"name":"Omar","roles":["viewer"]}],"total":2,"page":1}
That is perfectly valid JSON, but it is unreadable. APIs return minified JSON on purpose: no indentation, no line breaks, no spaces — the smallest possible payload travels fastest. But when you need to read it, debug it, or show it in documentation, you need it pretty-printed (also called beautified or formatted): each key on its own line, nested objects indented, arrays expanded.
In this guide you will learn exactly how to format a JSON API response using five methods — from a one-click online tool to terminal commands and code — so you can pick whichever fits your workflow.
Method 1: Use an Online JSON Formatter (Fastest)
If you just want the job done in seconds, paste the minified response into a free JSON formatter and hit Format. The tool parses the response and re-prints it with clean indentation — no installation, no account, nothing to download.
This is the best option when you are on someone else's machine, reviewing a response a colleague sent you, or debugging a webhook payload from a dashboard. A good formatter also validates as it formats: if the response has a syntax error, you get a clear message instead of silent garbage output.
Tip: the same tool has a minify mode that does the reverse — it strips all whitespace when you need the smallest possible payload for production.
Method 2: Browser DevTools (No Extra Tools Needed)
Modern browsers pretty-print JSON automatically. If you are debugging an API call in Chrome, Edge, or Firefox:
- Open DevTools (F12 or right-click → Inspect).
- Go to the Network tab and trigger the request.
- Click the request, then open the Response (or Preview) tab.
The browser renders the JSON as an expandable, syntax-highlighted tree — no pasting required. This is ideal for quick checks while developing, because you see the response exactly where it arrived.
Method 3: Format JSON in the Terminal with jq
If you live in the terminal, jq is the standard tool for working with JSON. Pipe any API response through it:
curl -s https://api.example.com/users | jq .
The trailing . tells jq to output the whole document, pretty-printed with 2-space indentation. jq can also drill into nested data without formatting everything:
curl -s https://api.example.com/users | jq '.users[0].name'
No jq installed? Python ships with a built-in equivalent:
curl -s https://api.example.com/users | python3 -m json.tool
Method 4: Pretty-Print JSON in Python
When you are already writing Python, the json module formats responses in one line:
import json, requests
response = requests.get("https://api.example.com/users")
data = response.json()
print(json.dumps(data, indent=2))
Use indent=2 for compact readable output or indent=4 for wider spacing. Add sort_keys=True to alphabetize keys — handy when you diff two responses. For production code, drop the indent and pass separators=(",", ":") to produce minified JSON instead.
Method 5: Pretty-Print JSON in JavaScript
In Node.js or the browser console, JSON.stringify takes an optional indent argument:
const pretty = JSON.stringify(response, null, 2); console.log(pretty);
The third argument (2) sets the indent level — use 4 for four spaces or "\t" for tabs. If you only have the raw response string, parse first, then stringify:
const pretty = JSON.stringify(JSON.parse(rawResponse), null, 2);
What If Formatting Fails? (Invalid JSON)
Every method above assumes the response is valid JSON. If a formatter throws an error or jq complains about "parse error", the response itself is broken — the usual suspects are trailing commas, single quotes instead of double quotes, unquoted keys, or comments that slipped into a config file. Do not guess: run it through a validator that points at the exact line and character, then work through the common JSON syntax errors and their fixes one by one. Fix first, then format.
All 5 Methods Compared
| Method | Best for | Speed | Needs install? |
|---|---|---|---|
| Online JSON formatter | Quick one-off formatting anywhere | Seconds | No |
| Browser DevTools | Debugging live API calls | Instant | No |
| jq | Terminal workflows, scripting | Seconds | No (stdlib) |
| Python json.dumps | Formatting inside Python code | Seconds | No (stdlib) |
| JSON.stringify | Formatting inside JS/Node code | Seconds | No |
Format for Humans, Minify for Machines
Remember the rule of thumb: format JSON when a human needs to read it (debugging, docs, code review) and minify it when a machine needs to move it (production APIs, config bundles, data exports). Minified JSON is typically 20–40% smaller — a meaningful saving on high-traffic endpoints.
One more thing you will run into: some API responses embed base64-encoded blobs (images, files, tokens) inside a field. Those stay unreadable even after pretty-printing — paste the encoded string into a base64 decoder to see what is actually inside.
Frequently Asked Questions
How do I format a JSON API response online for free?
Paste the minified response into a free online JSON formatter and click Format. The tool validates and re-prints the JSON with indentation in seconds, entirely in your browser.
Does formatting JSON change the data?
No. Pretty-printing only adds whitespace — indentation, line breaks, and spaces. The data, structure, and values stay exactly the same, and the formatted JSON parses identically.
Why does my API return JSON on one line?
APIs minify responses to reduce payload size and transfer time. One line of compact JSON downloads faster and costs less bandwidth than an indented version.
What is the difference between formatting and validating JSON?
A formatter reshapes valid JSON for readability; a validator checks whether JSON is syntactically correct and reports the exact location of errors. Most online tools do both at once.
Conclusion
Formatting a JSON API response takes seconds once you know the options: an online JSON formatter for instant results, browser DevTools for live debugging, jq or python -m json.tool in the terminal, and one-liners in Python or JavaScript when you are already coding. Pick the method that matches where you are working — and when the formatter complains, treat it as a signal to validate and fix the JSON first.