Skip to main content

JSON Formatter

Format messy JSON with 2-space, 4-space or tab indentation, or minify it, and see syntax errors with the position they occur. Runs entirely in your browser.

Paste JSON and get it back indented and readable, or minified for transport. Invalid input is reported with the parser's own message, which usually names the position of the problem, and the byte counter shows what minifying actually saves.

JSON Formatter
Indent
Paste some JSON...

// JSON Formatter: Features

Four output modes

Two-space indentation is the common default and what most style guides and formatters produce. Four-space indentation suits deeply nested configuration that you intend to read rather than edit. Tab indentation respects whatever width the reader has configured in their editor, which is the accessibility argument for it. Minify strips every optional space and newline, which is what you want for a payload rather than a file.

Validation comes free with formatting

The tool parses the input before it can reformat it, so a document that will not format is a document that is not valid JSON. The error shown is the browser's own parser message, which typically names the character position where parsing failed. That position is where the parser gave up rather than necessarily where the mistake is, so look slightly before it: a missing comma is usually reported at the start of the next key.

The mistakes that make JSON invalid

JSON is stricter than it looks and stricter than JavaScript. Keys must be double-quoted, so single quotes or bare words fail. A trailing comma after the last element of an array or object is a syntax error, even though most editors and JavaScript itself accept one. Comments are not permitted in any form. NaN and Infinity are not valid values. And a single quote is never a string delimiter. Nearly every "invalid JSON" report comes down to one of these five.

What minifying is worth

The byte counter shows the input and output sizes and the percentage saved, which is usually between 10 and 30 per cent for indented data. Whether that matters depends on the transport: over a connection with gzip or brotli compression enabled, whitespace compresses almost to nothing and the saving largely disappears. Minify for payloads where every byte is counted, and keep the formatting for anything a person will read.

Why you can paste a production API response here

Parsing and formatting run as JavaScript in your browser using the built-in JSON functions. API responses containing personal data, configuration files with credentials and payloads from a production incident can all be pasted here without leaving your machine. To turn the same document into TypeScript types, a JSON Schema or a list of paths, see the related tools in the Japanese edition. To compare two documents rather than tidy one, the JSON Diff reports only the values that actually changed.

// JSON Formatter: FAQ

What does the JSON formatter do?

It parses your JSON and re-serialises it with the indentation you choose, or with no whitespace at all if you pick minify. Because it has to parse the input first, it doubles as a validator: anything that will not format is not valid JSON, and the error message tells you where the parser stopped.

Why is my JSON reported as invalid when it looks fine?

The five usual causes are a trailing comma after the last item, single quotes instead of double quotes, unquoted keys, a comment, or a value such as NaN or undefined that JSON does not define. JavaScript object literals allow several of these, which is why code that works in a console fails as JSON.

Can I use comments in JSON?

Not in standard JSON. Some tools accept them as an extension, usually under the name JSONC or JSON5, and TypeScript configuration files are a common example. Standard parsers, including the one behind this tool and the one in your language's standard library, will reject them. If you need comments in configuration, TOML and YAML both support them.

Which indentation should I choose?

Two spaces is the default almost everywhere, including in the output of most language libraries, so choose it unless you have a reason not to. Four spaces reads better for deeply nested structures. Tabs let each reader set their own width, which some accessibility guidance prefers. For anything that a machine will read, use minify.

Does minifying meaningfully reduce transfer size?

Less than you might think, when compression is in play. Whitespace is extremely compressible, so over a gzip or brotli connection the difference between formatted and minified JSON is often a couple of per cent rather than the twenty the raw byte count suggests. Minify where compression is unavailable, where the payload is stored rather than transferred, or where a size limit is measured on the raw bytes.

Does formatting change the order of keys?

No. JSON objects have no defined ordering, but every mainstream parser preserves the order it encountered, and this tool re-serialises in that same order. What can change is the representation of numbers: a value written as 1.0 comes back as 1, and very large integers beyond the safe range lose precision, because they pass through JavaScript numbers.

How large a JSON document can it format?

No fixed limit, but very large documents become slow because the whole thing is parsed, re-serialised and rendered as text in the page. For multi-megabyte files a command line tool such as jq is a better fit. For anything you would reasonably read by eye, this is comfortable.

Can it repair broken JSON?

No, and that is deliberate. Guessing at the intended structure of a malformed document is how silent data corruption happens. The tool reports where parsing failed and leaves the correction to you.

What happens to duplicate keys?

The specification does not define behaviour, and in practice the last occurrence wins, which is what the browser's parser does here. That means a duplicated key is silently discarded during formatting. If a value seems to vanish, check whether the same key appears twice in the original.

Is the JSON I paste sent to a server?

No. The parsing and formatting happen in your browser and the document never leaves the page. Closing the tab discards it, and nothing is stored or logged.

// How to Use JSON Formatter

  1. Paste the JSON to format

    Put the document into the input box. A single-line API response, a configuration file or a fragment copied from a log are all fine, and formatting happens as you type.

  2. Pick the indentation

    Choose two spaces, four spaces or tabs to make the document readable, or minify to strip all optional whitespace. If the input is invalid, the parser error appears instead, naming where it stopped.

  3. Copy the formatted JSON

    Copy the formatted or minified output with one click. The byte counter underneath shows the input size, the output size and the percentage saved, which is worth checking before you rely on minifying to hit a size limit.

Category Data Formats