Why Pretty-Print at All?
Minified JSON is great for the wire; it is punishing for humans. Pretty-printing adds indentation and newlines so you can scan structure, spot missing keys, and diff changes.
Use minified in production, pretty in editors, logs a developer will actually read, and anywhere Git will diff the file.
The Two-Space Convention
Most tools and style guides use two-space indentation. It keeps files narrow enough to diff and wide enough to read.
Four spaces is common in some Python projects; tabs are rare and generally discouraged for JSON.
| Indent | Where you see it |
|---|---|
| 2 spaces | Default in Node, Prettier, VS Code |
| 4 spaces | Python json.dumps default when indent=4 |
| Tabs | Rare; not recommended for JSON |
Step-by-Step: In the Browser
The console is faster than any online tool for one-off cases.
const data = JSON.parse(text);
console.log(JSON.stringify(data, null, 2));Sort keys for stable diffs
Predictable output is easier to review.
const sorted = JSON.stringify(data, Object.keys(data).sort(), 2);Step-by-Step: In the Terminal
jq is the swiss-army knife for JSON on the command line.
# Pretty-print a file
jq . data.json
# Pretty-print from a pipe
curl -s https://api.example.com/orders | jq .
# Two-space indent (default is two)
jq --indent 2 . data.json > pretty.jsonAlternatives when jq is not available
Python is on almost every machine.
python -m json.tool data.json > pretty.jsonStep-by-Step: In Code
Every mainstream language has a one-liner.
JavaScript / Node.js
Third argument is the indent.
fs.writeFileSync("pretty.json", JSON.stringify(data, null, 2));Python
indent + sort_keys for readable, deterministic output.
import json
with open("pretty.json", "w", encoding="utf-8") as f:
json.dump(data, f, indent=2, ensure_ascii=False, sort_keys=True)Go
MarshalIndent replaces Marshal when you want pretty output.
b, err := json.MarshalIndent(v, "", " ")Editors and Formatters
You rarely need a website to format JSON.
- VS Code: Shift+Alt+F (Format Document).
- IntelliJ/WebStorm: Ctrl+Alt+L (Reformat Code).
- Prettier: --parser json on the command line.
- Vim: :%!jq . if jq is installed.
Real-World Examples
The formatting choice depends on the audience.
Git-committed fixtures
Always pretty-print with sorted keys to keep diffs small and reviewable.
Production API
Minify responses to save bytes; log pretty for developer debugging endpoints.
CSV → JSON export
Convert CSV Online produces pretty JSON out of the box, so stakeholders can open the file in any editor.
Common Mistakes
Small formatting issues cause big review pain.
- Mixing indent widths within one file.
- Losing the trailing newline (some tools require it).
- Turning off sort_keys and getting noisy diffs.
- Pretty-printing 100 MB responses in production logs.
- Trusting an online formatter to strip comments—JSON does not have comments.
Best Practices
A short list that keeps files pleasant.
- Use 2 spaces by default.
- Sort keys for committed files.
- End files with a newline.
- Prefer editor formatters over web tools for privacy.
- Minify at the network boundary, pretty at rest.
Why Use Convert CSV Online?
When your JSON originates from a CSV, Convert CSV Online is free, browser-based, and needs no account for everyday conversions. It produces pretty JSON directly, ready to commit or hand to stakeholders. Client-side workflows run on Windows, macOS, and Linux browsers.
Preview + prettify in one step
Convert the CSV and preview the JSON without a second tool.
Conclusion
Pretty-printing JSON is a one-liner in every language and a one-shortcut task in every editor. Use it for anything a human will read; keep the wire minified.
FAQ
How do I pretty-print JSON in the browser?
Use JSON.stringify(data, null, 2) in the console, or format the JSON in your editor with the built-in formatter (VS Code, WebStorm, Sublime).
How do I pretty-print JSON in the terminal?
Use jq: jq . data.json. If jq is not installed, python -m json.tool data.json also works.
What indent should I use?
Two spaces is the most common convention and matches Prettier and Node defaults. Four spaces is fine too—just be consistent.
Should I sort keys?
Yes for committed files—sorted keys make diffs easier to review. For runtime output, order rarely matters.
Can I pretty-print JSON without going online?
Yes. Use your editor, jq, or a language library. Web tools are convenient but not required.
Does pretty-printing change the data?
No. It only changes whitespace. Parsing pretty and minified JSON yields the same value.
References
Convert your CSV in the browser
Preview, clean, and convert CSV files free with Convert CSV Online—no installation and no account required for everyday conversions.