JSON Formatter & Validator

Make an unreadable API response readable — and find out exactly where the syntax breaks.

Status
0Keys
0Max depth
0 BOutput size

Runs in your browser. Everything you type or load here is processed locally by JavaScript on this page. Nothing is uploaded to Tooltrusty or to any third party.

What the jSON Formatter & Validator does

JSON is easy for machines to read and, when it arrives as one unbroken line, close to impossible for people. This formatter parses the text with the browser's own JSON engine and re-serialises it with indentation, so the structure becomes visible. Because it parses rather than pattern-matches, formatting doubles as validation: if the tool produces output, the JSON is genuinely valid.

When it is not valid, the error message tells you what the parser objected to and converts the character offset into a line and column, which is the part most formatters leave out. The three faults that account for most JSON errors are all easy to spot once you are pointed at the right line: a trailing comma after the last item in an object or array, single quotes instead of double quotes, and unquoted keys. All three are legal in JavaScript object literals and illegal in JSON, which is why they are so common.

Five actions are available. Format expands with your chosen indentation. Minify strips every optional space, typically cutting 20–40% from a pretty-printed file — worth doing before sending JSON over a network. Sort keys recursively alphabetises every object, which makes two API responses comparable in a diff tool even when the original key order differed. Escape as string turns a JSON document into a string literal you can embed inside another JSON document, and Unescape reverses it — a common need when a log entry has captured a payload as an escaped string.

The counters report how many keys the document contains, how deeply it nests and how large the output is.

How to use it

  1. Paste your JSON into the left box.
  2. Press Format to expand it, or Minify to compress it to a single line.
  3. If the status shows Invalid, read the message — it gives the line and column where parsing failed.
  4. Copy the result, or download it as a .json file.

A worked example

An API response arrives as one line. Pressing Format turns it into:

{
  "order": {
    "id": "ORD-4821",
    "total": 149.5,
    "currency": "GBP",
    "items": [
      { "sku": "TT-001", "qty": 2, "price": 49.75 },
      { "sku": "TT-014", "qty": 1, "price": 50 }
    ],
    "shipped_at": null
  }
}

Now suppose you add a trailing comma after "shipped_at": null, and press Format again. The status flips to Invalid and the message reads something like Unexpected token } in JSON at position 213 at line 11, column 3 — pointing at the closing brace that follows the stray comma, which is exactly where you need to look.

Frequently asked questions

Why does my JSON fail to parse when it looks fine?

In order of likelihood: a trailing comma after the last element, single quotes instead of double quotes, unquoted object keys, an actual line break inside a string, or a stray byte-order mark at the very start of the file. All are valid in JavaScript and invalid in JSON.

Does formatting change my data?

No. Formatting only changes whitespace. The one thing to be aware of is that JSON has no distinction between integers and floats, so a value written as 50.0 re-serialises as 50 — the value is identical, the notation is not.

Is it safe to paste an API response containing customer data?

Yes, in the sense that matters: parsing happens in JavaScript on this page and nothing is transmitted. That is exactly why this tool has no server component — API payloads with real data are the most common thing people paste into formatters.

What does sorting the keys achieve?

It makes two documents comparable. JSON objects have no defined key order, so two responses containing identical data can produce a huge diff purely from ordering. Sort both, then compare them in the Text Diff Checker and only real differences remain.