How to Format API Response JSON

Beautify, validate, inspect, and export JSON returned by APIs.

API responses are often returned as minified JSON — a single long line with no whitespace, no indentation, and no line breaks. That format is efficient for network transmission but nearly impossible to read when you are debugging a failed request, verifying a payload shape, reviewing what changed between deployments, or checking whether a field name matches your code. This guide covers every practical scenario where you need to format, inspect, validate, and export an API response, and explains how to do it without sending your data to a server.

Where API JSON Comes From

Before you can format a response, you need to get the raw JSON text. Here are the most common sources and how to copy from each:

Browser DevTools — Network Tab

Open DevTools (F12 or right-click → Inspect), click the Network tab, then trigger the request by refreshing the page or clicking the action that fires it. Click the request in the list, then click the Response or Preview tab. Copy the raw response text and paste it into the formatter.

If the response tab shows a formatted tree already (Chrome's default), switch to the raw response view or use Copy Response from the right-click menu on the request row to get the actual minified text.

Postman and Insomnia

Both tools display JSON responses in a formatted view by default. To get the raw response for pasting elsewhere, click the Raw tab in Postman, or switch the Insomnia response viewer to Raw mode. Copy the full text from there.

curl on the Command Line

A curl request like curl https://api.example.com/users/42 prints the response body to the terminal. Pipe it through a formatter if you want readable output directly in the terminal:

curl https://api.example.com/users/42 | python3 -m json.tool

Or copy the raw output and paste it into JSON Formatter Hub for full validation, tree view, and export.

Server Logs and Application Logs

Many backend frameworks log request and response payloads as single-line JSON strings. Extract the JSON portion — everything from the first { or [ to the matching closing brace or bracket — then paste it into the formatter.

Webhook Payloads

Services like Stripe, GitHub, Slack, and Shopify send webhook payloads as JSON. Most webhook inspection tools (Webhook.site, ngrok inspect, Stripe Dashboard) show you the raw payload. Copy it directly for formatting and inspection.

Before and After: What Formatting Does

Here is a realistic minified API response from a user endpoint:

Minified (hard to read):

{"status":"ok","user":{"id":42,"name":"Ava","email":"ava@example.com","roles":["admin","editor"],"preferences":{"theme":"dark","notifications":true}},"meta":{"requestId":"req_8f3a","durationMs":94,"cached":false}}

Formatted (easy to read):

{
  "status": "ok",
  "user": {
    "id": 42,
    "name": "Ava",
    "email": "ava@example.com",
    "roles": ["admin", "editor"],
    "preferences": {
      "theme": "dark",
      "notifications": true
    }
  },
  "meta": {
    "requestId": "req_8f3a",
    "durationMs": 94,
    "cached": false
  }
}

The formatted version makes it immediately clear that preferences is a nested object, roles is an array of strings, and meta contains request metadata. Debugging the structure — verifying field names, checking types, confirming nesting — takes seconds instead of minutes.

Step-by-Step: Format an API Response

  1. Copy the raw JSON response from your API client, browser DevTools, terminal, or log output.
  2. Open the JSON Formatter.
  3. Paste the response into the left editor panel.
  4. Click Format. The tool applies indentation and validates the syntax simultaneously. If there is a syntax error, it highlights the problem with line and column information.
  5. If the JSON is invalid (a common occurrence with log-extracted payloads or AI-generated responses), click Auto-fix to repair trailing commas, single quotes, and unquoted keys.
  6. Use the View JSON Tree tab to explore nested objects and arrays interactively. Expand and collapse nodes to inspect only the section you care about.
  7. If the response contains a flat array of objects, use the Table View to see the data as rows and columns.
  8. Click Export/Download to save the output as formatted JSON, minified JSON, CSV, YAML, or XML.

Validating That a Response Matches Your Expectation

Formatting reveals the structure — but sometimes you need to verify that a response matches an expected shape. Two situations where this matters:

Checking field names and types

After formatting, visually scan the tree for the fields your code depends on. If your frontend expects user.profile.avatarUrl but the API returns user.avatar_url, you will catch the mismatch here before it becomes a runtime error.

Comparing two responses

If you are debugging a difference between a staging API and a production API, between an old response and a new one after a deploy, or between an expected test fixture and an actual response, use the Compare JSON tool. Paste one response on the left and one on the right — it highlights every added, removed, and changed field so you do not need to scan two walls of formatted text manually.

Working with Large API Responses

Responses from search endpoints, data exports, and paginated result sets can be tens of thousands of lines when formatted. For responses under about 5 MB, the formatter handles them without issue in any modern browser. For very large responses — over 5 MB — consider these approaches:

Exporting API Responses to Other Formats

Once an API response is formatted and valid, you can export it to other formats directly from the formatter:

Privacy: Why Browser-Based Formatting Matters for API Responses

API responses often contain sensitive data: authentication tokens, personal information, internal IDs, pricing data, or business logic. Pasting these into an online formatter that uploads data to a server creates a security risk. JSON Formatter Hub runs entirely in your browser — no data is sent to any server, ever. You can safely format authentication headers, user records, payment responses, and internal API payloads without any data leaving your machine.

Frequently Asked Questions

My API response starts with )]}' or some other prefix. How do I format it?

Some APIs (notably certain Google APIs) prepend a non-JSON security prefix to responses to prevent JSON hijacking. Strip everything before the first { or [ before pasting into the formatter. The actual JSON starts after that prefix.

The response is wrapped in a callback function. How do I extract the JSON?

JSONP responses look like callbackFunction({"key": "value"}). Remove the function name and parentheses, leaving only the JSON object or array inside, then paste that into the formatter.

Can I load the API response directly from a URL?

Yes — use the Load from URL feature in the formatter. Enter the API endpoint URL and the tool fetches the response and loads it into the editor automatically. This works for public APIs and endpoints that do not require authentication headers.

I formatted the response but cannot find the field I am looking for. What should I do?

Use the tree view and expand nodes level by level. If the field name differs from what you expected (camelCase vs snake_case, different plural form, abbreviated name), look for it systematically by expanding each object. For very large responses, use your browser's Ctrl+F within the formatted JSON text to search for a specific key name.

Try what you just learned — paste your JSON into the formatter and validate it instantly. Free, browser-only, no data sent anywhere.

Related Guides

Ready to format an API response? Paste your payload into the browser-private formatter.

Open JSON Formatter