API Response Formatter

Paste what your terminal or network tab handed you, headers and guard prefixes included. The format is detected, the wrapper is peeled off, and a bad byte gets reported with its line and column instead of a shrug.

Try a responseJSON detected
Raw response0 lines0 B
Formatted0 lines0 B
Paste a raw response, then press Format to read it on the right.
Depth0
Nodes0
Keys0
Widest list0
Top level
nothing to list

A formatter that answers Unexpected token H in JSON at position 0 is telling you something real. The H is the HTTP/1.1 200 OK line you copied along with the body. Almost every failed paste has a cause of that kind, and the fix is peeling one layer off the front rather than blaming the API.

What actually lands on your clipboard

Response bodies pick up passengers on the way to your editor. Terminal output includes the status line, security middleware writes a guard prefix, and message queues hand you one document per line. The Clean the paste toggle removes the following before parsing, and the status bar names whatever it stripped.

What you pastedWhere it came fromHandling
HTTP/1.1 200 OK plus header linescurl -i, curl -v, or Copy as response in a browser network tabStatus line and every header up to the blank line are dropped
)]}', on line oneXSSI protection used by Google APIs and several Java frameworksThe guard is removed, along with the while(1); and for(;;); variants
callback({...});A JSONP endpoint reached through a script tagThe wrapper is unwrapped when the inside parses as JSON
An invisible character before {UTF-8 byte order mark written by .NET or a PHP file with whitespace before the opening tagThe mark is stripped, so the parse reaches the real first byte
"{\"order_id\":\"A-2291\"}"A field holding a JSON document that was serialised twiceOne layer of string encoding is unwrapped and the result parsed again
Several objects, one per lineLog streams, bulk exports, and the Elasticsearch and OpenAI streaming formatsDetected as JSON Lines, with each record parsed and numbered separately
A trailing comma or a // noteA fixture edited by hand, or a config file saved as JSON with commentsRemoved as a fallback after the strict parse fails, and reported when applied

Turn the toggle off when you want the strict result. Debugging a client library that rejects a body is exactly the case for it, since the point is to see the same failure the library sees.

Turning a parse error into a location

Browser JSON errors report a character offset, not a line. The panel below the editors converts the offset to a line and column, prints the three lines around it with a caret under the byte, and the Go to the bad character button moves the cursor there. Three messages cover most of what you will hit:

  1. Paste the body untouched, including anything above it.
  2. Read the badge in the toolbar to see which format was detected. A response you expect to be JSON showing up as Plain text means the front of the document is wrong.
  3. Press Validate for a yes or no answer with no reformatting.
  4. If the parse fails, follow the caret to the byte and look at the character before it, which is where the real mistake usually sits.

The shape panel

Under the panes sit four numbers taken from the parsed document rather than the text: nesting depth, total node count, total key count, and the length of the longest array. Top level keys appear beside them.

Depth is the number worth watching. A payload nested eight levels deep forces every consumer to write defensive accessor code, and mobile clients pay for it in parsing time on older devices. Widest list tells you whether an endpoint returns everything at once, which is the difference between a page of results and an accidental full table scan. Compare the same endpoint before and after a schema change and the four numbers show what moved.

Sort keys reorders every object alphabetically at all levels. Two responses from different environments become diffable that way, because key order stops being noise. Use it before pasting both into a diff tool, and leave it off when key order is part of what you are inspecting.

XML responses carry more than tags

SOAP envelopes and legacy REST services arrive as one long line. Formatting indents by nesting level, keeps namespace prefixes exactly as written, and leaves CDATA blocks untouched, since the whitespace inside them is content rather than layout.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Invoice not found</faultstring></soap:Fault></soap:Body></soap:Envelope>

A SOAP fault returns HTTP 200 in most implementations, so an HTTP status check alone will not catch it. Format the body and look for a Fault element inside Body. That is the failure signal in this protocol, and the Top level list makes it visible without reading the whole document.

Attributes against child elements

The key count for XML counts attributes, not elements, so a document that models data as attributes reports differently from one using child elements for the same fields. Both are valid. Knowing which one an endpoint uses matters when you map the response onto a JSON model, because attributes usually end up prefixed and children do not.

YAML is stricter than it looks

Config APIs and Kubernetes-style endpoints return YAML, and the parse follows the YAML 1.1 rules the popular libraries use. Two habits cause most surprises:

Tabs are illegal for indentation anywhere in a YAML document, and a duplicate key at the same level is an error in strict parsers while others silently keep the last value. The error line reported here points at the mapping where the parser gave up, which is normally one line past the real problem.

Where this formatter stops

Everything runs in your browser. No request leaves the page, which rules out several things you might want:

The trailing comma repair is the one place where the output differs from strict input, and the status line always names it when it happens. Everything else preserves your values exactly, including number precision beyond what JSON parsers round to.

Working with one format only? The JSON Fixer repairs broken payloads more aggressively, and the XML Pretty Print page handles documents that are not API responses at all.

Questions about messy API responses

What people run into between a raw body and something readable.

Why does my response fail to parse when it looks like valid JSON?

Something sits in front of the opening brace. The usual suspects are the HTTP status line copied from curl -i, an XSSI guard such as )]}', or a UTF-8 byte order mark you cannot see. Leave the Clean the paste toggle on and the status bar will name whatever was removed.

What does the )]}' prefix at the start of a response mean?

It is an XSSI guard. Adding those characters makes the body invalid JavaScript, so a third party site cannot load the endpoint through a script tag and read the data. Client libraries strip the prefix before parsing. This page does the same.

My payload field contains a JSON string instead of an object. What happened?

The value was serialised twice, usually by a service that stored the document as text and then encoded the envelope around it. Paste the whole response and the outer layer is unwrapped so both levels format together. Load the Double encoded sample to see the pattern.

How do I format a stream of JSON objects, one per line?

Paste the whole stream. Multiple valid documents separated by newlines are detected as JSON Lines and each record is parsed and formatted separately, with the record and line number reported if one of them fails. Set the format control to JSON Lines to force that reading.

Does the tool send my response anywhere?

No. Parsing and formatting run in your browser through JavaScript loaded with the page. Nothing is uploaded, stored, or logged, which is why there is no URL field for fetching a response directly.

Why is my YAML boolean coming back as false when I wrote no?

YAML 1.1 treats no, yes, on, and off as booleans. A country code, an answer field, or any value where NO means text needs quotes around it. The same rule turns 2.4 into a number, so version strings need quoting too.

Does this check a response against my OpenAPI schema?

No. This page checks that a document is well formed and reports its shape. Contract checks against JSON Schema, OpenAPI, or an XSD need a validator that reads your schema file, which is a separate job.

What do the depth and node numbers under the panes measure?

They come from the parsed document rather than the text. Depth is the deepest nesting level, nodes counts every value including objects and arrays, keys totals the object keys at every level, and widest list is the length of the longest array. Run the same endpoint before and after a change to see what moved.