Allin1Tool
Developer ToolsRuns in your browser

JSON Formatter

Format, minify or validate JSON with a collapsible tree, key sorting, and warnings when parsing quietly loses data.

Share:

JSON Formatter workspace

Source Editor

Input

Press Ctrl/Cmd + Enter to run.

Your draft is kept in this tab only (sessionStorage) and disappears when the tab closes. .

Result Console

Using JSON Formatter

  1. Paste your document into the editor, or press Load example to start from a sample.

  2. Choose a Mode: Format to indent, Minify to compact, or Validate to check only.

  3. Set the indent to 2 spaces, 4 spaces or Tab, and tick Sort object keys A-Z for a canonical order.

  4. Press Run, then read the notice above the result for precision loss or collapsed duplicate keys.

  5. Copy or download the output, or send it through the JSON to XML and JSON to YAML buttons.

One page handles indenting, compacting and checking JSON, since all three begin with the same parse. Alongside the result it inspects the raw text for the things JSON.parse discards without complaint: integers beyond the safe range, exponents that overflow to null, and duplicate keys where only the last survives.

JSON Formatter, Minifier and Validator

Three separate JSON pages used to live on this site and they mostly repeated one another. They are now a single page with a Mode selector, because the parse step is identical in every case and only what happens afterwards differs.

Choosing a mode

Format reindents the document at two spaces, four spaces or a tab and builds the collapsible tree beneath the output. Minify removes every space that sits outside a string and reports the byte count before and after. Validate hands your text back untouched and tells you only whether it parses, which is what you want when you need to confirm a payload is well-formed without anything rewriting it.

Independent of the mode, the Sort object keys A-Z checkbox reorders every object recursively. Do that to both sides before a comparison: two payloads carrying identical data in a different key order otherwise produce an enormous and entirely uninteresting diff in JSON Compare.

The three losses that never raise an error

JSON.parse is not lossless, and none of the three ways it discards information produce so much as a console warning. Paste this and switch to Validate:

{
  "orderId": 9007199254740993,
  "distance": 1e400,
  "status": "new",
  "status": "archived"
}

Every bracket is correct, so it parses. Then look at what came back. orderId is now 9007199254740992, one less than you wrote, because JavaScript stores numbers as 64-bit floats and the exact integers stop at 9007199254740991. distance overflows the range of a double and lands as null on the way back out. And status is "archived" — a repeated key is not an error in JSON, and the last one silently wins.

This page scans the raw text alongside the parse and names each of those cases, with the path and the original literal. Snowflake IDs, database bigints and ledger amounts are the usual victims. If you control the producer, send large integers as strings, the way an id_str field exists next to a numeric id in several public APIs.

The tree

A successful Format also renders the document as a tree you can walk. Nodes expand and collapse from the keyboard as well as the mouse, arrays show their length, and each leaf shows its type, so an integer that arrived as "42" is visible as a string rather than something you have to squint at.

XML and YAML output

Two buttons above the result convert the formatted document. The XML conversion wraps each key as an element name and each array item in a repeated element. The YAML conversion emits block style with two-space nesting. Both are one-way and intended for pasting into a config file or a test fixture, not for round-tripping.

What this page deliberately will not do

It does not strip comments, because a document containing them is not JSON and quietly accepting it teaches you the wrong thing about your own pipeline. It does not validate against a schema — use Ajv or a language-native validator for that. And it no longer offers to repair broken input. The previous auto-fix replaced every apostrophe it found while trying to normalise quotes, which turned {"msg":"it's fine"} into something that would not parse at all. A repair step that can corrupt valid data is worse than no repair step.

Nothing you paste leaves the tab. There is no network call in this code path at all, which matters more than it sounds when the document you are checking is an API response with a bearer token still in it. Your draft is held in sessionStorage for this tab only, and the "Clear it now" link wipes it immediately.

Frequently asked

Why did my large integer change value after formatting?

JavaScript stores every number as a 64-bit float, so exact integers stop at 9007199254740991. A Snowflake ID or a database bigint past that point is rounded during parsing. This page scans the raw text separately and names each affected path, so the loss is visible instead of silent. Send such values as strings if you control the producer.

My document has the same key twice. Which one survives?

The last one. A repeated key is not a syntax error in JSON, and the earlier occurrences are discarded during parsing without any warning. The formatter reports every collapsed key by path so you can see what disappeared.

Can it strip comments or repair broken JSON?

No, and both omissions are deliberate. Comments are not part of JSON, so accepting them would hide a real problem in your pipeline. The old repair step replaced every apostrophe while normalising quotes, which turned valid documents into unparseable ones, so it was removed rather than patched.

What is the difference between the Minify and Format modes?

Format reindents at your chosen width and builds the interactive tree. Minify strips every space outside a string and reports the byte count before and after. Validate changes nothing at all and only tells you whether the document parses.