How to Format JSON Online (and Why Indentation Matters)
Updated · 5 min read · MetaSol Technologies
Formatting JSON means adding consistent line breaks and indentation so its structure is visible. The data does not change; only the whitespace between tokens does.
Formatting in four steps
- Open the JSON Formatter.
- Paste your JSON, drop a
.jsonfile onto the editor, or click Upload. - Choose an indentation style and press Format (or Ctrl + Enter).
- Copy the result or download it.
If the input is invalid, the formatter does not guess. It highlights the problem and explains it, for example: Trailing comma before '}' — line 12, column 18.
Which indentation should you use?
- 2 spaces: the most common choice for JSON. It is used by most JavaScript tooling and keeps deep structures from drifting off the right edge.
- 4 spaces: common in .NET and Python projects. It is easier to scan when nesting is shallow.
- Tabs: each reader picks their own visual width. They are less common in JSON files you share.
The most important thing is consistency within a project. Many teams enforce it with an .editorconfig file or a formatter in CI.
Sorting keys
JSON objects are unordered, so {"b":1,"a":2} and {"a":2,"b":1} contain the same data. If you compare two files as text, though, a different key order shows up as a change. Turning on Sort keys gives every document the same canonical order, which makes diffs and code reviews far cleaner. Arrays are never re-ordered, because array order does matter.
Keeping numbers intact
A subtle trap: many online formatters parse your JSON into JavaScript values and serialise it again. That silently changes data:
| Input | After a naive JavaScript round trip |
|---|---|
12345678901234567890 |
12345678901234567000 |
{"2":"b","1":"a"} |
{"1":"a","2":"b"} (reordered) |
1.50 |
1.5 |
The formatter on this site works on a lossless syntax tree, so every number, escape sequence and key order is written back exactly as you entered it.
Compact arrays for documentation
Standard formatting gives every array item its own line, so ["read", "write"] takes four lines. For docs and tickets, the JSON Pretty Printer keeps short lists of simple values on one line and expands everything else.
Formatting very large files
Files of several megabytes format in a second or two. The editor stays responsive because it renders only the visible lines. For files above about 2 MB, the tree view opens collapsed so you can expand only what you need.