JSON Formatter

Beautify, minify and validate JSON with the error position shown

Runs entirely in your browser. Your data never leaves this device.

Input · JSON
Output

How to use it

  1. Paste JSON into the input panel. Validation and formatting run as you type.
  2. Switch to Minify to strip all whitespace, or enable Sort keys to order keys alphabetically.
  3. If the document is invalid, the status bar shows the line and column where parsing failed.

Reading the error position

The single most useful thing a JSON tool can do is tell you where the problem is. Browsers report a character offset, which is useless when you are staring at a 4,000-line file, so this page converts that offset into a line and column.

One subtlety worth knowing: the reported position is where the parser gave up, not always where the mistake is. A missing closing brace is reported at the end of the document, because that is where the parser finally runs out of input. A missing comma is reported at the start of the next key, because that is the first token that could not follow the previous one. When the position looks innocent, look at the line above it.

What JSON does not allow

JSON is deliberately smaller than most people remember. The specification (RFC 8259) permits objects, arrays, strings, numbers, true, false and null — and nothing else. Four things that feel like they should work, but do not:

  • Trailing commas. [1, 2, 3,] is invalid. This is the most common single cause of parse failures, because most programming languages allow it.
  • Single quotes. Strings must use double quotes. {'a': 1} is not JSON, it is a JavaScript object literal.
  • Unquoted keys. {a: 1} is likewise JavaScript, not JSON.
  • Comments. There is no comment syntax at all. Tools that accept them (tsconfig.json, VS Code settings) are using JSONC, a superset.

Two more constraints catch people out less often but hurt more when they do. Numbers have no defined precision limit in the spec, but every practical parser uses a 64-bit float — so an ID above 2^53 will come back subtly wrong. And duplicate keys are undefined behaviour: parsers accept them and keep the last one, so data can disappear silently between systems.

Beautify or minify — when each matters

Formatting with indentation is for humans: reading a payload, diffing two versions, filing a bug. Minifying is for the wire, where every byte crosses a network. In practice the difference matters less than it used to, because gzip and Brotli compress repeated whitespace very efficiently — a minified payload is often only a few percent smaller after compression.

Where minifying does still pay off is anywhere the JSON is stored uncompressed and read often: a database column, a cache entry, a message queue payload. There, the saving is real and permanent.

Sorting keys

JSON objects have no defined key order, but the text does — and that is what your diff tool compares. Two payloads that are semantically identical will produce a noisy diff if the keys came out in a different order. Sorting both sides first turns that noise into an empty diff, which makes this one of the quickest ways to compare two API responses by hand.

Frequently asked questions

Why does my JSON fail with 'Unexpected token'?

Almost always one of four things: a trailing comma after the last item, single quotes instead of double quotes, unquoted keys, or a comment. JSON allows none of these — the error position tells you where the parser gave up.

Can JSON contain comments?

Not in standard JSON. Formats like JSONC and JSON5 add them, and tsconfig.json accepts them, but a strict parser will reject them. This tool follows the standard.

Does formatting change my data?

Only whitespace, unless you enable Sort keys. Note that duplicate keys are silently collapsed to the last one by any JSON parser, including this page — if your input had duplicates, the output will not.

Are very large numbers safe?

Not always. JavaScript parses numbers as 64-bit floats, so integers beyond 2^53 lose precision. If you handle large IDs, transmit them as strings.

What does 'depth' in the status bar mean?

How many levels of nesting the document has. It is a quick sanity check — an unexpectedly deep document usually means a structure you did not intend, and deep nesting is what makes JSON slow to query.

Is my JSON sent to a server?

No. Parsing and formatting happen in JavaScript on this page, so it is safe to paste production payloads.

Related tools

browse category →

Last updated: