About the JSON Formatter
This formatter takes any JSON text, checks it against the JSON specification, and rewrites it with consistent indentation. It handles the full grammar: nested objects and arrays, Unicode escapes, exponent numbers, and empty containers. Because the output is produced by re-serialising the parsed value rather than by inserting whitespace, the result is always valid JSON, and key order is preserved exactly as it appeared in the input.
Formatting runs automatically 300 milliseconds after you stop typing, and again when you change the indent width. Choose two, three or four spaces, or a tab. The stats line below the panes shows the input and output size and how long the parse took, which is useful when you are deciding whether a payload is small enough to inline in a request.
If the input is not valid JSON, the output stays empty and an amber message tells you the line and column of the first problem, for example a single-quoted string, a trailing comma, or a missing closing brace. The same position is underlined in the input pane. For input that is almost JSON, such as a JavaScript object literal copied from source code, the JSON Fixer will repair it first.
Everything happens in your browser. Nothing you paste is uploaded, logged or stored, so it is safe to format API responses that contain tokens or personal data.
How to use
- Paste your JSON into the left pane, or click Upload to load a
.jsonfile, or Sample to try the tool. - The formatted result appears on the right as you type. Change Indent if you want 4 spaces or tabs.
- If you see an amber error, go to the line and column it names, fix the character, and the output updates.
- Click Copy to put the result on your clipboard or Download to save it as a file. Swap sends the result to the JSON Minifier.
Common questions
- Does this JSON formatter change the order of keys?
- No. Keys stay in the order they appear in your input. If you want them alphabetical, use the JSON Sorter.
- Why does it say "unexpected token" when my JSON looks fine?
- The most common causes are single quotes around strings or keys, a trailing comma before a closing bracket, comments, or an unquoted key. JSON does not allow any of these. The error message names the exact line and column, and the JSON Fixer can repair most of them automatically.
- What is the largest file it can format?
- It comfortably formats files of a few megabytes in well under a second on a laptop. Very large files, above roughly 50 MB, may exhaust browser memory because the whole document must be parsed into an object.
- Is my JSON uploaded anywhere?
- No. The parser and serialiser run as JavaScript inside this page. You can verify it by opening the network tab of your browser: no request is made when you format.
- How do I format JSON with 4 spaces instead of 2?
- Use the Indent selector in the toolbar. The output re-renders immediately with the new width; you do not need to click Format again.