JSON Formatter and Validator: Pretty-Print, Minify, Find the Error

The document is read where it is typed; the parse stops at the first character the grammar does not allow and reports the line and the column.

Puts each object's members in order of their names, which makes two versions of a document easier to compare. It is the one option that changes more than whitespace.

The document is parsed and written back by JavaScript running in your browser. Nothing you paste is uploaded, stored or logged, and the page makes no network request while it works.

valid JSON, indented two spaces { "id": 128, "name": "paper and ink", "tags": [ "json", "whitespace" ], "nested": { "ok": true, "note": null } }

bytes in 95
bytes out 140
lines out 12
nesting 2 levels 2 objects and 1 array around 6 values
read 95 bytes of text valid JSON
shape 2 objects, 1 array, 6 values 2 levels deep
whitespace one level of indent is two spaces 12 lines
size 95 bytes in 140 bytes out

How do you format JSON?

A JSON formatter reads a document, checks it against the grammar and writes it back with the whitespace you choose. Same values, same order, different bytes on screen.

  1. Paste the document into the box. It is checked where it sits, as you type.
  2. Choose how it should be written: one value to a line at two spaces, four spaces or a tab, or minified onto a single line. Sorting the names A to Z is optional.
  3. Read the verdict first, valid JSON or not, then the byte count of what you pasted beside the count of what came back.
  4. If it does not parse, look at the line and column the page names. That character is where the grammar ran out, which is rarely where the mistake feels like it is.

What a strict parser refuses, and where it stops

Every document below was run through this page's own parser; the last column is what it said. A trailing comma, a string in single quotes, a name without quotes, a comment, NaN and Infinity are all outside the JSON grammar, so a strict parser stops at the character where one of them appears rather than guessing what was meant.

What a strict parser refuses, and where it stops
What is writtenThe documentStrict parserWhat this page says
A comma before the closing brace{"a": 1,}RefusedLine 1, column 9: expected a name in double quotes, found a closing brace.
A string in single quotes{'a': 1}RefusedLine 1, column 2: expected a name in double quotes, found a single quote.
A name with no quotes{a: 1}RefusedLine 1, column 2: expected a name in double quotes, found 'a'.
A comment{/* id */ "a": 1}RefusedLine 1, column 2: expected a name in double quotes, found a slash.
NaN, or Infinity{"a": NaN}RefusedLine 1, column 7: expected a value, found 'N'.
A byte order markU+FEFF, then {"a": 1}RefusedLine 1, column 1: expected a value, found a byte order mark (U+FEFF).
One name written twice{"a": 1, "a": 2}AcceptedBoth pairs kept, in the order they were written, and the name "a" reported as repeated.

Worked Example: One Document, Two Sets of Whitespace

Indenting this document adds 45 bytes and changes nothing else. The same document is 95 bytes on one line and 140 bytes across 12 lines at an indent of two spaces, and all 45 bytes of the difference are whitespace.

read 95 bytes of text valid JSON
shape 2 objects, 1 array, 6 values 2 levels deep
whitespace one level of indent is two spaces 12 lines
size 95 bytes in 140 bytes out

95 bytes on 1 line becomes 140 bytes across 12 lines, and every byte of the difference is whitespace.

Formatting a JSON document changes its whitespace and nothing else: the same members come back in the same order, carrying the same values, written across more lines or fewer.

The extra 12 lines buy a machine nothing: minify to send, indent to read.

What Does Formatting Not Change?

JSON is not JavaScript

JSON is not JavaScript. The two look alike, and most JavaScript object literals are not valid JSON, because the literal syntax allows names without quotes, single quotes, trailing commas and comments, and the JSON grammar allows none of them. A snippet lifted out of a source file was never JSON; it only looked like it.

Reshaping the data is a different job

Formatting takes a JSON document in and gives the same document back. Writing the same data out in another format is a different job with different questions - which name becomes which column, what happens to nesting - and this page does not do it. What comes back is JSON, every time.

Order is not data, and neither is a repeat

Members come back in the order they were written, and a name written twice keeps both pairs; the grammar fixes neither, so this page changes nothing it was not asked to change and reports the repeat rather than dropping a pair. Sorting the names is a box you tick, never a default.

Frequently Asked Questions

What does unexpected token in JSON mean?

The parser met a character the grammar does not allow there and gave up, without saying which one or where. This page names both. A comma left at the end of a line, with the closing brace on the next, reports: Line 3, column 1: expected a name in double quotes, found a closing brace.

What is the difference between formatted and minified JSON?

Whitespace, and nothing else. The document above is 95 bytes minified and 140 bytes at an indent of two spaces, with the same values in the same order.

Why does a JSON file look correct but still fail to parse?

A byte order mark sits in front of the opening brace and shows up in no editor, so a document that looks correct can stop the parse on its very first character; this page names that character instead of reporting an unexpected token.

Why do large numbers change when JSON is parsed?

JSON sets no limit on how long a number is, and a JavaScript parser reads every one as a 64-bit float, so 12345678901234567890 comes back as 12345678901234567000. This page copies the digits of a number through untouched and never reads one as a float.

Is it safe to paste JSON into an online formatter?

For this page, yes, and the note under the box says why. For any other, the test is whether the document leaves your machine: open the network panel, paste something, and watch for a request.

How do you validate JSON online?

Paste it into the box above. The answer opens with a verdict, valid JSON or not, and a refusal names the line, the column and the character where the parse stopped.

There is an index of the site's other tools.