ModernCalcs

API Response Formatter

Paste a raw API response — JSON, XML, or plain text — and get it auto-detected and pretty-printed.

{
  "id": "usr_1",
  "name": "Jane Doe",
  "roles": [
    "admin",
    "editor"
  ],
  "active": true,
  "meta": {
    "createdAt": "2024-01-15T10:00:00Z"
  }
}

API Response Formatter: One Box for JSON or XML

Copying a raw response straight from a network tab or a curl command often lands you with one unbroken line of text — and whether it's JSON or XML isn't always obvious at a glance when it's minified. This tool detects which format you've pasted and pretty-prints it accordingly, without needing to pick a mode yourself.

Formula
first non-whitespace character: { or [ → JSON; < → XML; otherwise → plain text

JSON is validated and reformatted via JSON.parse/stringify; XML is validated via the browser's native DOMParser.

Why Auto-Detection Instead of a Mode Toggle

When you're pasting a response you didn't write, you don't always know its format before you've looked at it — auto-detecting from the first character removes a step and avoids the confusing 'invalid JSON' error you'd get from trying to parse XML as JSON (or vice versa) with the wrong mode selected.

Real XML Validation, Not a Guess

XML formatting uses the browser's own `DOMParser`, the exact same engine that parses XML/HTML documents natively — malformed XML (unclosed tags, unquoted attributes, multiple root elements) is caught with a real parser error, not a heuristic guess.

Practical Examples

Formatting a Minified JSON Response

Pasting a one-line JSON API response.

  • 1.Paste the response
  • 2.Auto-detected as JSON
  • 3.Get indented, readable output

Formatting a SOAP/XML Response

Pasting a raw SOAP envelope.

  • 1.Paste the XML
  • 2.Auto-detected as XML
  • 3.Get properly nested, indented markup

What's Supported

  • JSON objects and arrays
  • XML documents (including SOAP envelopes)
  • Plain text passthrough for anything else

Good Use Cases

  • Making sense of a minified response copied from dev tools
  • Quickly checking whether a response is even valid JSON/XML
  • Preparing a response for inclusion in documentation
  • Comparing formatted output against expected structure

Frequently Asked Questions

How does format detection work?

It's based on the first non-whitespace character: { or [ is treated as JSON, < is treated as XML, and anything else is passed through as plain text. This matches the two structured formats REST APIs overwhelmingly use for response bodies.

How is XML validated?

Using the browser's native `DOMParser`, which parses the document and reports a `parsererror` node for malformed XML — the same parser the browser itself uses, not a hand-rolled approximation.

Why might my XML fail to parse even though it looks fine?

XML is stricter than HTML — every tag must be properly closed or self-closing, attribute values must be quoted, and there must be exactly one root element. A response that 'looks like XML' but breaks one of these rules will fail DOMParser's strict parsing.

Does this handle SOAP XML responses?

Yes — SOAP envelopes are just XML, so they're detected and formatted the same way as any other XML response.

Is my response data sent anywhere?

No, detection and formatting happen entirely in your browser.