Pretty-Print JSON
Last updated: 26 September 2026
Pretty-printing means rewriting JSON with indentation and line breaks so a person can read it. Here is a box that does it in your browser, followed by the one-liners for terminals, editors and code.
What changes and what does not
Pretty-printing inserts whitespace between tokens: line breaks, indentation, and a space after each : and ,. Nothing else moves. Property order is preserved, string contents are untouched — including spaces inside them — and no numbers are rounded. Parse the file before and after and you get identical data, which is why minifying and pretty-printing are reversible operations on the same document.
Pretty-print JSON in a terminal
For files too large or too sensitive to paste into a browser:
jq '.' config.json— the standard choice;.is the identity filter, so all the work is the pretty output.python3 -m json.tool config.json— ships with Python; add--indent 4to change the width and--sort-keysto reorder them.node -e 'const f=require("fs");f.writeFileSync(1,JSON.stringify(JSON.parse(f.readFileSync(process.argv[1],"utf8")),null,2))' config.json— the same parser your application uses.
All three read stdin, so a live API response works without saving it first:
curl -s https://api.example.com/status | jq .curl -s https://api.example.com/status | python3 -m json.tool
When you only want one branch of a big document, filter instead of scrolling: jq '.limits' config.json prints just that object, and jq -r '.regions[]' lists array items one per line.
Pretty-print inside your code
- JavaScript —
JSON.stringify(value, null, 2). The third argument is the indent; omitting it gives compact output. - Python —
json.dumps(data, indent=2, ensure_ascii=False). Withoutensure_ascii=Falseevery non-ASCII character becomes a\uXXXXescape, which is valid but unreadable. - Go —
json.MarshalIndent(v, "", " ");json.Marshalalone is always compact. - Rust —
serde_json::to_string_pretty(&value)?. - Java —
new GsonBuilder().setPrettyPrinting().create().toJson(value). - PHP —
json_encode($value, JSON_PRETTY_PRINT).
In an editor
VS Code: paste, then Shift+Option+F on macOS or Shift+Alt+F on Windows and Linux to format the document; set "editor.tabSize": 2 to control the width. IntelliJ and WebStorm: Cmd+Option+L (Ctrl+Alt+L) to reformat. Sublime Text needs a package such as Pretty JSON. Most editors will refuse to format a file with a syntax error, so fix the error first — the validator reports the line and column.
When you should not pretty-print
Pretty output is bigger — often 20–45% bigger, and more for deeply nested data — so sending it over the network costs real bytes on every request. Anything a machine consumes should stay compact: API responses, bundled assets, localStorage values. Minify those instead, and keep indentation for files a human reads and reviews in a diff.
Two other cases worth knowing: a several-megabyte document will make a browser tab or editor crawl, so slice it with jq rather than opening it whole; and if the goal is comparing two payloads, sort the keys first — the formatter's recursive key sort puts two files in the same order so a diff shows only real changes.
Frequently Asked Questions
What does pretty-printing JSON do?
It rewrites JSON with line breaks and indentation, one value per line, so a human can read the structure. Only formatting whitespace is added: the data, key order and every string value stay exactly as they were, and parsing the pretty version gives the same result as parsing the original.
How do I pretty-print JSON in a terminal?
With jq: run jq '.' file.json to print it indented. Without jq, python3 -m json.tool file.json does the same job, and node -e with JSON.parse plus JSON.stringify using a two-space indent works too. Any of them can read a pipe, so curl -s https://api.example.com/data | jq . pretty-prints a live response.
Why does my pretty-printed JSON have escaped unicode?
Some writers escape every non-ASCII character by default — Python's json.dump turns an accented letter into a six-character \uXXXX escape. Pass ensure_ascii=False to keep the real characters, which stays valid JSON and is far easier to read.
Should pretty-printed JSON be committed to Git?
Yes, when people edit the file, because a diff of one-property-per-line JSON shows exactly what changed. The opposite is true for generated payloads: minify what crosses the network and keep formatted JSON for anything a human reads.