Skip to content
R3XTools

JSON Formatter

Pretty-print or minify JSON, with the exact line and column of any syntax error.

Input

Paste JSON here

or drop a .json file

Lines
0
Size
0 B

Output

Output appears here.

Lines
0
Size
0 B
Tab indents · Esc leaves the editor
Options
JSON.stringify(value, null, 2)

Processed locally in your browser. Your JSON is parsed and formatted in this tab and never sent to a server.

Reference

What formatting actually changes

Formatting parses the document and prints it again with consistent indentation and spacing. It changes only insignificant whitespace: keys, values, ordering and types come back exactly as they went in. Minifying is the same operation with the whitespace removed, which is what you want before putting JSON in a header, an environment variable or a URL.

Because the text is re-printed from the parsed value rather than patched in place, a document has to be valid before it can be formatted. That is why the error panel is as detailed as it is.

Reading the error

Errors report the line and column of the first character that could not be accepted, along with what the parser expected instead. The line is marked in the editor gutter, and Go to error moves the caret there.

The position is where the parser noticed the problem, which is often one token after the mistake. A missing comma on line 7 is usually reported at the start of line 8, because that is where the document stopped making sense.

Mistakes JSON does not allow

JSON is much stricter than a JavaScript object literal. These are the differences that account for most parse failures:

Not allowedWhy
{'a': 1}Strings and property names must use double quotes.
{a: 1}Property names are always quoted, even when they look like identifiers.
[1, 2,]Trailing commas are invalid in both arrays and objects.
// commentJSON has no comment syntax of any kind.
NaN, InfinityNot JSON values. Use null or a string.
007Numbers cannot have leading zeros.
.5 1.A decimal point needs digits on both sides.
'\n' in a stringLiteral line breaks must be escaped as \n.

Sorting keys

Sorting rewrites every object so its keys are in ascending order, recursively. It is useful when you want to diff two API responses that agree on content but not on key order. It does change the document, so do not sort output you intend to byte-compare against a signature or checksum.

Large documents

Formatting runs on the main thread, but input handling is decoupled from it, so typing stays responsive while a large document is reprinted. Syntax highlighting switches off above roughly 120,000 characters — colour is the expensive part, and the editor stays usable without it.

Questions

Is my JSON uploaded anywhere?
No. The parser and formatter are JavaScript running in this tab. Open your browser's network panel while you use it and you will see no request. That matters because the JSON people format is usually an API response with real customer data in it.
Why does my JSON fail to parse when it looks fine?
The three usual causes are a trailing comma before a closing brace, single quotes instead of double quotes, and an unquoted key. All three are legal JavaScript and none are legal JSON. The error message here gives you the line, column and character that broke it rather than a generic 'unexpected token'.
What is the difference between formatting and minifying?
Formatting adds newlines and indentation so a person can read the structure. Minifying removes every byte that is not required, which is what you want before sending JSON over the wire. Both produce the same data — only the whitespace changes.