What the JSON formatter does
Paste JSON or open a .json file, then choose what to do with it:
- Format indents the data with 2 or 4 spaces or with tabs, so you can read it.
- Minify removes all the whitespace, for the smallest possible payload.
- Validate checks the syntax. If something is wrong, you get the line and column of the first error, the line itself with a marker, and a plain explanation of what to fix.
- Sort keys orders the properties of every object alphabetically, which makes two versions of a document much easier to compare.
- Tree shows the structure as a collapsible outline with item counts, which helps you find your way around a large API response.
Everything runs in your browser, nothing you paste is uploaded, and documents of several megabytes are handled in well under a second on a typical computer.
Exact numbers and no silent changes
A formatter built on JavaScript's own JSON.parse turns every number into a 64-bit floating-point value. Integers above 9,007,199,254,740,991, such as large database IDs, come out rounded, and the formatted copy no longer matches the original. This formatter keeps every number, string and escape sequence exactly as written and only changes the whitespace, plus the key order if you ask for it.
It also warns about duplicate keys. They're allowed by the JSON grammar but are almost always a mistake, because most parsers silently keep only the last value.
Common errors and how to fix them
- Trailing comma: a comma after the last item, as in
[1, 2,]. JavaScript accepts it, JSON doesn't. - Single quotes: JSON strings and property names need double quotes.
- Unquoted property names: write
{"name": 1}, not{name: 1}. - Comments: JSON has no comments, so remove any
//or/* */parts. - More than one value: a JSON document holds exactly one value. Wrap several objects in
[ ]to make a list. Files with one JSON object per line (JSON Lines) need to be checked line by line. - Special values:
NaN,Infinityandundefinedaren't valid JSON. Usenullor a number.
If you collect API data through proxies, the Python and Node.js guides show how to send requests through a proxy and read the JSON that comes back.