How to use the Json formatter
- 1Paste JSON into the input, or load the sample to see how it works.
- 2Choose an indent style (2 spaces, 4 spaces or tab) and click Format, or click Minify for the most compact output.
- 3Tick Sort keys to order every object's keys alphabetically, at every level of nesting.
- 4Copy the output or download it as a .json file. If there is an error, the message points to the line and column to check.
How it works
The input is parsed with the browser's standard JSON parser, the same strict parser JavaScript applications use, and then serialized again with the indentation you chose. Because the text is fully parsed first, formatting also acts as a validity check: nothing is output from invalid JSON.
Minifying serialises with no whitespace between tokens. Whitespace inside strings is part of the data and is left untouched. Sorting keys rebuilds each object with its keys in alphabetical order; arrays keep their original order, since the order of array elements is meaningful.
The JSON is processed locally. API keys, tokens or customer records in a payload are not sent to any server, which is worth checking before pasting production data into any online tool.
Worked examples
Formatting a compact API response
- 1Input: {"id":42,"name":"Ada","roles":["admin","editor"],"active":true}
- 2Format with 2 spaces
- 3Each key moves to its own line; the roles array is expanded with one item per line
A readable, indented document with exactly the same data.
Comparing two configs with Sort keys
- 1File A lists keys as port, host, debug; file B as debug, host, port
- 2Format both with Sort keys on
- 3Both now read debug, host, port
A text diff shows only real value differences, not ordering noise.
Finding a syntax error
- 1Input contains a trailing comma: {"a": 1, "b": 2,}
- 2Format reports an error at line 1, column 17, where the closing brace appears after a comma
Remove the comma after 2 and the document formats normally.
Should I use 2 spaces, 4 spaces or tabs?
It is a style choice with no effect on the data. Two spaces is the most common in JavaScript projects and in package.json files; four spaces is typical in Python-oriented tools; tabs let each reader set their own width. Match whatever the project or team already uses.
When should JSON be minified?
Minify when size or bandwidth matters: embedding JSON in a URL or HTML attribute, storing it in a database column, or sending it over the network. Web servers usually gzip responses anyway, which removes most of the benefit for API traffic. Keep formatted JSON for anything a person will read or edit, such as config files in version control.
Frequently asked questions
Does formatting change my data?
No. Only whitespace between tokens changes, unless you enable Sort keys, which reorders object keys. Values, types and array order stay the same.
Can it format JSON with comments?
No. Comments are not part of the JSON standard, so the strict parser reports them as errors. Remove the comments first, or keep such files as JSONC or JSON5 in tools that support those formats.
Why did my large numbers change after formatting?
JavaScript stores numbers as 64-bit floating point, which can represent integers exactly only up to 9,007,199,254,740,991. Larger IDs lose precision when parsed, so APIs usually send them as strings.
Is there a size limit?
There is no fixed limit, but very large documents of tens of megabytes may make the page slow, since everything is processed in your browser.
Is it safe to paste API responses containing tokens?
The formatter runs locally and does not send the text anywhere. Still, treat secrets carefully and rotate any key that you have shared somewhere you should not have.