Skip to content
ToolShelf

JSON formatter & validator

Format JSON with the indent you want, minify it back down, sort its keys, and get the line and column of a syntax error rather than a message about position 4,812.

Your JSON

Your JSON stays in this tab. The work is done by JavaScript in your browser. None of it is uploaded, logged or saved, and the tool keeps working with the network off.

How to print it

Indent
Key order

Formatted

Formatted JSON appears here as you type.

Where it runs

In your browser, using the same JSON.parse your own code uses. Nothing is uploaded and nothing is stored: load the page, disconnect the network, and it still works. That matters for this tool more than most, because the JSON a developer needs to read is usually a real response from a real system, and quite often has somebody’s data in it.

Using the browser’s own parser is a deliberate choice rather than a shortcut. A hand-written parser would be a second opinion about what counts as valid JSON, and the opinion that matters is the one held by the runtime your code will use.

The four things that are not JSON

Almost every “but it looks fine” turns out to be one of these. All four are perfectly good JavaScript, which is exactly why they catch people out.

  • Trailing commas. {"a": 1,} and [1, 2, ] are both rejected.
  • Single quotes. JSON strings and keys use double quotes, always.
  • Unquoted keys. {a: 1} is an object literal, not JSON.
  • Comments. There is no comment syntax in JSON at all.

Two things JSON quietly changes

Duplicate keys collapse. {"a":1,"a":2} is valid, and every parser keeps the last one. The formatted output has a single key and the first value is simply gone. The tool does not do this to you. Your code does the same thing, but it is worth seeing before you assume the output matches the input.

Large numbers lose precision. JSON has no integer type, so numbers become double-precision floats holding about fifteen significant digits. An ID of 12345678901234567890 comes back as 12345678901234567000. Anything above 9,007,199,254,740,991 has to be quoted as a string in the JSON itself to survive; no formatter can recover one that was not.

Sorting keys, and when to

Key order carries no meaning in JSON, so sorting changes nothing about what a document says. What it changes is comparability: two config files written by different people, or two API responses from different versions, become byte-identical if their contents match, and a diff shows only real differences instead of reshuffling.

Array order is never touched, because there it is the data. An array is a sequence and reordering it would be changing the document rather than tidying it.

Questions

Is my JSON sent anywhere?
No. The formatting and the validation both run in JavaScript in your browser, using the same JSON.parse your own code uses. Nothing is uploaded, logged or stored. You can turn the network off after the page loads and the tool keeps working, which is the easiest way to check the claim yourself.
Why does it say my JSON is invalid when it looks fine?
The three usual causes are a trailing comma after the last item, keys or strings in single quotes instead of double, and comments. All three are legal in JavaScript and none of them is legal in JSON. Unquoted keys are the fourth. The error points at the line and column whenever the browser tells us where it is.
Why does the error sometimes not give a line number?
Because the browser does not always say where the problem is. For some errors it reports a position and for others it only quotes a fragment of your document. Rather than guessing from the fragment, which would sometimes underline the wrong line. The tool says what is wrong and leaves the location out.
What happened to my duplicate keys?
JSON allows the same key twice, and every JavaScript parser keeps only the last one. So {"a":1,"a":2} formats to a single "a": 2 and the first value is gone. This is not something the tool does to you. It is what your code will do with the same document, but it is worth knowing before you treat the formatted output as identical to the input.
Why did my long ID number change?
JSON has no integer type, so every number becomes a double-precision float, which holds about 15 significant digits. An ID like 12345678901234567890 comes back as 12345678901234567000. Any identifier larger than 9,007,199,254,740,991 has to be a string in the JSON to survive the trip, and no formatter can rescue one that is not.
What does sorting the keys do?
It puts every object's keys in alphabetical order, at every level, leaving arrays in the order they were written. Object key order carries no meaning in JSON, so nothing about the document changes, but two files that differ only in key order become byte-identical, which makes them diffable. Array order is data and is never touched.
What is the difference between minified and formatted JSON?
Only whitespace. Minified JSON has none of it, which makes it smaller to send and unreadable to people; formatted JSON adds indentation and line breaks for reading. Both parse to exactly the same thing. Minify for storing and transmitting, format for reading and reviewing.
Can it handle a large file?
Within reason. Everything happens in the browser tab, so the limit is your machine's memory and patience rather than an upload size. A few megabytes is comfortable, tens of megabytes will make the page think. For anything larger, a command-line tool such as jq will be happier than any web page.

More tools