Skip to content
WGX

JSON Formatter

Make JSON readable, make it small, or find out exactly what is wrong with it.

Indent with

Nothing to hand? .

JSONExample

Valid JSON

There is nothing here yet. Paste some JSON to check it.

The error message is the point

Formatting JSON is a single function call, and every tool that offers it does the same thing. Where they all stop is the moment it fails: Unexpected token } in JSON at position 42 is what the browser says, and it names neither the line you are looking at nor the mistake you made. This page finds the position itself — the same way in every browser — and then says what is actually wrong.

The five mistakes that account for nearly all of them

  • A comma after the last item. JavaScript allows it, JSON does not. This is the most common failure by a wide margin.
  • Single quotes.{'a': 1} is a JavaScript object, not JSON. Strings and property names both need double quotes.
  • Unquoted property names.{a: 1} for the same reason.
  • Comments. JSON has none. Editors that accept // are reading JSONC, which is a different format that shares the name.
  • Values JSON does not have.NaN, Infinity, undefined — and True, False and None, which arrive when something was written by hand after being read in Python.

Formatting, minifying and validating are one operation

A formatter has to parse the document before it can indent it, so it validates whether it says so or not. A minifier is the same parse with the whitespace left out. That is why this is one page rather than three: the work is identical and only the last step differs.

Neither direction sorts your keys and neither changes your data. The keys keep the order they arrived in — this tool will not sort them, because a sorted document diffs against the original on every line that moved, and comparing two responses is half of why people format them in the first place.

Your IDs come back with the digits they went in with

The usual way to format JSON is to parse it and write the result out again. That looks lossless and is not: JavaScript numbers are doubles, so a nineteen-digit ID does not survive the trip. Paste {"id": 12345678901234567890} into most formatters and you get back {"id": 12345678901234568000} with nothing said about it — and a Snowflake ID from Twitter, Discord or Instagram is exactly that long.

Three smaller versions of the same problem travel with it: 1.50 comes back as 1.5, a key written twice keeps only its last value, and keys that are whole numbers jump ahead of the rest because JavaScript orders them first. This page lays out the characters you pasted instead of a copy of them, so all four survive. Only the spaces between the values change.

The tree is for finding things

Indented text is for reading a document you already understand. When it is three thousand lines and you want one field, the tree under the result is faster: each branch says how much it holds, and closing the ones you do not care about leaves what you do. It is built from the browser's own disclosure control, so it opens with the keyboard and works the way the rest of the web does.

Nothing is uploaded

Your browser parses the text; nothing is sent anywhere and nothing is executed. This is worth stating plainly because of what people paste here: an API response, complete with the token that fetched it. A formatter that posts your document to a server to prettify it has been handed your credentials, and you would have no way of knowing.

Questions

How do I format JSON?

Paste it into the box and press Format. The document is checked as you type, so if it cannot be formatted you will already know why — with the line, the column and the mistake — before you press anything.

Why does my JSON say it is invalid?

Nearly always one of five things: a comma after the last item in a list or object, single quotes instead of double, a property name without quotes, a comment, or a value JSON does not have such as NaN or undefined. Each of those is named specifically here rather than reported as "unexpected token".

Are trailing commas allowed in JSON?

No. JavaScript allows them and JSON does not, which is why they are the single most common reason a document fails to parse. Editors that accept them are usually reading JSONC or JSON5, which are different formats that share the name.

What is the difference between formatting and minifying?

They are the same operation with opposite settings. Formatting adds indentation so a person can read the document; minifying removes every space between the values so a network moves fewer bytes. Neither changes the data, and one undoes the other exactly.

Does formatting change my data?

No. Only the whitespace changes. Most formatters read the document into JavaScript values and write those back out, which quietly changes four things: an id longer than about 16 digits loses precision, so 12345678901234567890 comes back as 12345678901234568000; 1.50 becomes 1.5; a key written twice keeps only its last value; and keys that are whole numbers move ahead of the rest. This one lays out the text you pasted rather than a copy of it, so every literal, every key and their order all survive exactly.

Will it keep a long ID exactly as I pasted it?

Yes. A Snowflake, Twitter or Discord ID is nineteen digits, which is longer than a JavaScript number can hold exactly, so a formatter that parses your document before writing it out gives you back a different ID with nothing said. Formatting and minifying here copy the digits across unchanged.

What happens to a key that appears twice?

Both are kept, and you are told which key it was. JSON allows a name to appear twice; a JavaScript object does not, so most tools silently keep the last one. Keeping both is the honest answer, but whatever reads the document next will probably keep only the last — which is worth knowing before it does.

Is my JSON sent anywhere?

No, and this matters here more than anywhere else on the site: what people paste into a JSON formatter is usually an API response, and API responses carry tokens. The text is parsed by your own browser, never executed and never uploaded. The test suite for this page watches what the formatter asks the network for and fails if any of it could carry the text.