Developer Guide

How to Format API JSON Responses — Quick & Free

You hit an API endpoint. You get back a wall of minified JSON — thousands of characters on a single line with no whitespace. Now you need to actually read it. Here is how to turn that mess into clean, indented, readable JSON in seconds.

The Problem: Minified API Responses Are Unreadable

APIs return minified JSON to save bandwidth. That is great for machines, but terrible for developers debugging, exploring, or documenting an API. A typical REST API response from a service like Stripe, GitHub, or Shopify might look like this:

Raw API Response (minified)
{"data":{"id":"cus_R8x2kLpNqO","object":"customer","name":"Jane Park","email":"jane@example.com","created":1711843200,"metadata":{"plan":"pro","seats":5,"trial_ends":"2026-04-15"},"subscriptions":{"data":[{"id":"sub_4nX9pKm","plan":{"id":"plan_pro_monthly","amount":4900,"currency":"usd","interval":"month"},"status":"active","current_period_end":1714521600}]},"default_source":"card_1Px9rK"},"has_more":false}

Good luck finding the trial_ends date or checking the subscription status in that. Now compare with the formatted version:

Formatted (pretty-printed)
{ "data": { "id": "cus_R8x2kLpNqO", "object": "customer", "name": "Jane Park", "email": "jane@example.com", "created": 1711843200, "metadata": { "plan": "pro", "seats": 5, "trial_ends": "2026-04-15" }, "subscriptions": { "data": [ { "id": "sub_4nX9pKm", "plan": { "id": "plan_pro_monthly", "amount": 4900, "currency": "usd", "interval": "month" }, "status": "active", "current_period_end": 1714521600 } ] }, "default_source": "card_1Px9rK" }, "has_more": false }

Same data. Completely different experience. You can immediately see the structure, find specific fields, verify nesting levels, and spot anomalies.

3 Ways to Format JSON API Responses

1

Use an online JSON formatter (fastest)

Paste your JSON into the Pure-Flon JSON Formatter. It validates and formats instantly, entirely in your browser. No data is uploaded to any server. Ideal when you are working with API keys, tokens, or user data that should not leave your machine.

2

Use the command line

Pipe your API response through jq or Python. Both produce indented, readable output directly in your terminal:

# Using jq (install: brew install jq) curl -s https://api.example.com/users/1 | jq . # Using Python (no install needed) curl -s https://api.example.com/users/1 | python3 -m json.tool # Save formatted output to file curl -s https://api.example.com/users/1 | jq . > response.json
3

Use your code editor

In VS Code: open a .json file, press Shift+Alt+F (Windows/Linux) or Shift+Option+F (Mac) to auto-format. In JetBrains IDEs (WebStorm, IntelliJ): Ctrl+Alt+L / Cmd+Option+L. This reformats the entire file with proper indentation.

Format Your JSON Now — Free
No signup · No data upload · Validates + formats in your browser

Common JSON Errors in API Responses (And How to Fix Them)

Sometimes the JSON you get from an API is not just minified — it is broken. Maybe you copied it incorrectly, or the API returned an error wrapped in HTML. Here are the most common JSON syntax errors and how to fix them:

Error Example Fix
Trailing comma {"a": 1, "b": 2,} Remove the comma after the last item. JSON does not allow trailing commas (unlike JavaScript).
Single quotes {'name': 'Jane'} Replace all single quotes with double quotes. JSON requires double quotes for strings and keys.
Unquoted keys {name: "Jane"} Wrap all keys in double quotes: {"name": "Jane"}. This is valid JavaScript but not valid JSON.
Missing comma {"a": 1 "b": 2} Add a comma between key-value pairs: {"a": 1, "b": 2}.
Comments {"a": 1 // count} Remove all comments. JSON does not support comments of any kind (use JSONC or JSON5 if you need them).
HTML wrapping <html>...{"error":"..."} The API returned an error page instead of JSON. Check the HTTP status code and Content-Type header.

A good JSON formatter catches all of these and shows you the exact line and character where the error occurs, so you know exactly what to fix.

When You Need to Format JSON

Debugging API integrations

When your code gets an unexpected response from a third-party API, the first step is to look at the raw response. Formatting it reveals the structure immediately — you can see if a field is missing, nested differently than you expected, or returning an unexpected type (string instead of number, array instead of object).

Exploring new APIs

When evaluating a new API (Stripe, Twilio, OpenAI, GitHub), you hit endpoints in Postman or curl to understand the response structure. Formatting the response lets you map out the data model before writing any code. It is much faster than reading API docs for complex nested objects.

Writing documentation

API documentation needs formatted JSON examples. Copy the raw response, paste into the formatter, and you get clean indented JSON ready for your docs. Consistent 2-space or 4-space indentation makes documentation look professional and is easier to diff when responses change.

Comparing two responses

When you need to compare API responses (before/after a change, staging vs production, v1 vs v2), formatting both consistently makes differences immediately visible. Format both with the same indentation, then use a diff tool. Without formatting, even identical responses with different whitespace will show false differences.

Storing configuration files

Many tools use JSON for config files (package.json, tsconfig.json, .eslintrc.json). When you edit these by hand, proper formatting prevents syntax errors and makes git diffs cleaner. A formatter catches mistakes before your build tool throws a cryptic parse error.

Power User: jq Recipes for API Responses

If you work with APIs daily, jq is essential. Here are the most useful patterns for processing API responses on the command line:

# Extract a single field curl -s api.example.com/user | jq '.data.email' # Get all IDs from an array curl -s api.example.com/users | jq '[.data[].id]' # Filter array items curl -s api.example.com/orders | jq '[.data[] | select(.status == "active")]' # Count items curl -s api.example.com/products | jq '.data | length' # Pretty print with sorted keys curl -s api.example.com/config | jq '-S .' # Convert to CSV-like output curl -s api.example.com/users | jq -r '.data[] | [.id, .name, .email] | @csv'

For quick one-off formatting where you already have the JSON copied, an online formatter is faster than opening a terminal. For repeated API work, jq is unbeatable.

Try the JSON Formatter
Paste · Format · Copy. That is it.

Frequently Asked Questions

Why are API responses returned as minified JSON?

APIs minify JSON to reduce payload size and transfer time. Removing whitespace, newlines, and indentation can shrink a response by 10-30%. This matters at scale — an API serving millions of requests per day saves significant bandwidth by stripping formatting. The JSON is functionally identical whether minified or pretty-printed; formatting is purely for human readability.

Is there a difference between JSON formatting and JSON validation?

Yes. Formatting (pretty printing) takes valid JSON and adds indentation and line breaks to make it readable. Validation checks whether a string is valid JSON at all — catching issues like missing commas, unquoted keys, trailing commas, or mismatched brackets. A good JSON formatter does both: it validates first, then formats. If the JSON is invalid, it shows you exactly where the syntax error is.

Can I format JSON with nested objects that are 10+ levels deep?

Yes. JSON formatters handle any nesting depth. Deeply nested structures are actually where formatters provide the most value — trying to read a 10-level-deep minified JSON string without formatting is nearly impossible. The Pure-Flon formatter processes everything client-side, so even large deeply-nested payloads format instantly without upload limits.