JSON formatter and validator
Pretty-print, minify or validate JSON in the browser, with the line and column of the first error and an option to sort keys.
Paste JSON and press Format.
What the tool does
Format parses the text with the browser's JSON parser and writes it out again with the indent you chose, one key per line, nested objects and arrays indented under their parent. Minify writes it with no whitespace at all, which is what you want in a URL or a config that must be small. Validate checks the text without changing it. All three use JSON.parse, so what this page accepts is exactly what a JavaScript program accepts.
Reading the error
When the text is not valid JSON the result shows the parser's message and, where the browser reports a position, the line and column of the first problem. The usual causes, in order of how often they come up:
- A trailing comma after the last item in an object or array. JavaScript allows it; JSON does not.
- Single quotes around strings or keys. JSON strings use double quotes only, and keys are always strings.
- Comments. JSON has no comment syntax. Strip
//and/* */lines before parsing, or use a JSON5 tool if the file is meant to have them. - Unquoted keys, as in
{name: 1}. Write{"name": 1}. - Special values:
NaN,Infinityandundefinedare not JSON. Numbers cannot have a leading plus or a bare leading dot either. - A stray character before or after the value, often a byte-order mark, a log prefix, or a second JSON object pasted after the first.
Sorting keys
Sorting orders every object's keys alphabetically, at every level. It changes nothing about the data (JSON objects are unordered by definition) but makes two documents easy to diff and makes a large config easier to scan. Arrays keep their order, because order in an array is data.
Numbers, dates and big integers
JSON.parse turns every number into a double-precision float, so integers above 2^53 (about 9 × 10^15) lose precision: an id like 12345678901234567890 comes back rounded. If you see the last digits change after formatting, that is why; treat such ids as strings in your own code. Dates are just strings in JSON; the formatter does not touch them.
Privacy
Nothing you paste leaves the page. There is no server-side formatter, no analytics on this page, and the copy button uses the browser's clipboard on your device.