Format a REST API Response
REST APIs return compact, minified JSON to save bandwidth, but that makes the response nearly impossible to read during development and debugging. This example shows a realistic API response with a nested user object and a pagination block — exactly the kind of structure you'd get from a users list endpoint. Pasting it into the formatter instantly reveals the full hierarchy with consistent two-space indentation, making it trivial to spot unexpected fields or missing keys. When developers integrate with third-party APIs, they often receive undocumented response shapes that differ from the API documentation. Formatting the raw response is always the first debugging step: it tells you whether the status field is a string or a number, whether the data wrapper is an object or an array, and whether pagination lives at the top level or inside a meta block. Key parts of this example include the status field at the top level (a common envelope pattern), a nested data.user object carrying the actual resource, a data.pagination object with page, perPage, and total, and a meta block with request tracing information. Each of these nested levels is easy to miss in a minified one-liner but immediately obvious once formatted. Real-world scenarios where this matters: debugging a mobile app that shows blank screens because the response shape changed, comparing staging and production API responses to find environment-specific discrepancies, and writing integration tests where you need to assert specific nested values. Tips and pitfalls: watch for numeric IDs that look like integers in JSON but need to be handled as strings in JavaScript to avoid precision loss above 2^53. Also check that boolean values use true/false rather than the strings "true"/"false", which some APIs accidentally return. To customise this example, replace the hardcoded values with a real API response from your browser's Network tab or from curl. The formatter accepts any valid JSON regardless of size or nesting depth.
{"status":"success","code":200,"data":{"user":{"id":42,"name":"Jane Smith","email":"[email protected]","role":"admin"},"pagination":{"page":1,"perPage":20,"total":137}},"meta":{"requestId":"req_8f3a2b","duration":34}}FAQ
- Why is API JSON returned minified?
- Servers strip whitespace from JSON responses to reduce payload size and save bandwidth, especially for high-traffic APIs.
- Can I format nested objects and arrays?
- Yes. The formatter handles arbitrarily deep nesting and renders each level with consistent indentation.
- Does formatting change the data?
- No. Formatting only adds whitespace. The data values, keys, and structure remain identical to the original.
Related Examples
Well-designed API error responses are what separates APIs that developers love f...
Format a Webhook PayloadWebhooks are HTTP POST requests that third-party services send to your server wh...
Explore Deeply Nested JSONDeeply nested JSON is one of the most common sources of confusion when working w...