Format a JSON Response for Debugging
An API response arrives as one unbroken line, which is fine for a machine and useless for a person. Formatting indents the structure so you can see nesting, spot a null where an object should be, and copy a single value without guessing where it ends.
Find the break before reading the values
Indentation makes the shape visible, so a missing object or an array that should have three items becomes obvious. Look at the structure first: most integration bugs are a field that is null, missing or nested one level deeper than the client expects.
Validate before formatting
A response that fails to parse usually means truncated output or an error page served with a JSON content type. Validation names the position of the problem, which is faster than reading the payload by eye.
Keep secrets out of shared logs
Responses often carry tokens, session identifiers and personal data. Format and inspect locally, and redact before pasting into a ticket, chat or issue tracker. Once pasted into a third-party service, the value should be treated as public.
Frequently asked questions
- Why does formatting fail on my response?
- The payload is probably not valid JSON. Common causes are a truncated response, a trailing comma, single quotes instead of double quotes, or an HTML error page returned with a JSON content type.
- Does formatting change the data?
- No. Indentation and line breaks are whitespace and do not alter values or their types. Minifying again restores a compact payload.
- How do I find one field quickly?
- Search for the key name rather than scrolling the indented output. In a large response that is faster than reading the tree, and it shows every occurrence rather than only the first.