JSON Pretty Print
JSON Pretty Print
How JSON Pretty Print works
Last updated: November 2026JSON pretty print (also called beautify or format) takes compact or minified JSON and adds indentation and line breaks to make the structure immediately readable. The terms pretty print, beautify, and format are all used interchangeably for this operation.
Paste JSON into the left panel and click Beautify (or just paste — it formats automatically). Select 2-space or 4-space indent from the toolbar. The right panel shows the formatted output.
All processing runs entirely in your browser using JSON.stringify() — your data never leaves your machine.
JSON Formatting Reference
Pretty printing adds whitespace to make structure visible at a glance:
Before (minified)
{"name":"Alice","roles":["admin","user"],"active":true} After (2-space indent)
{
"name": "Alice",
"roles": [
"admin",
"user"
],
"active": true
} | Indent style | Common use | Node.js |
|---|---|---|
| 2 spaces | prettier, eslint, VS Code default | JSON.stringify(d, null, 2) |
| 4 spaces | Python json.tool, some style guides | JSON.stringify(d, null, 4) |
| Tab | Rare — editor-dependent width | JSON.stringify(d, null, '\t') |
Tips & Tricks
2 spaces is the universal default
Most JSON tooling (prettier, eslint, VS Code) defaults to 2-space indent. Use 4 spaces only if your project style guide requires it — mixing will cause noisy git diffs.
Tab indent works in some editors
In Node.js, JSON.stringify(data, null, '\t') produces tab-indented JSON. Some editors render tabs at different widths, so this is rarely used in practice.
Pretty printing validates simultaneously
JSON.stringify first parses the input — if parsing fails, it throws a SyntaxError with the position of the first error. Pretty printing is therefore a free syntax check.
python -m json.tool for quick CLI use
python3 -m json.tool file.json is available on any machine with Python and prints to stdout. Pipe to a file with > out.json.
The replacer argument filters keys
JSON.stringify(data, ['name', 'age'], 2) only includes the listed keys in the output — useful for redacting sensitive fields before logging.
toJSON() controls serialization
If an object has a toJSON() method, JSON.stringify calls it instead of serializing the object directly. Date objects use this — they serialize to ISO 8601 strings automatically.
Pretty Print JSON Programmatically
Node.js
const fs = require('fs');
const raw = fs.readFileSync('data.json', 'utf8');
const pretty = JSON.stringify(JSON.parse(raw), null, 2);
fs.writeFileSync('data.pretty.json', pretty); Python
import json
with open('data.json') as f:
data = json.load(f)
with open('data.pretty.json', 'w') as f:
json.dump(data, f, indent=2) CLI
# jq with no filter — pretty prints with 2-space indent jq . data.json # 4-space indent jq --indent 4 . data.json # Python one-liner python3 -m json.tool data.json
Frequently Asked Questions
What is JSON pretty print?
- JSON pretty print means formatting JSON with indentation and line breaks so it is easy for humans to read. It is the same as JSON beautify or JSON format — it takes compact or minified JSON and adds whitespace to make the structure clear.
What is the difference between pretty print and minify?
- Pretty print adds whitespace and indentation for human readability. Minify removes all unnecessary whitespace for the smallest possible output, which is better for network transfer and production API responses.
Is my JSON data sent to a server?
- No. All formatting runs entirely in your browser using JavaScript. Your data never leaves your machine and no account is required.
How do I pretty print JSON in Node.js?
- Use
JSON.stringify(data, null, 2)— the third argument sets the indent size. For 4-space indent usenull, 4, for tab indent usenull, '\t'. How do I pretty print JSON in Python?
- Use
json.dumps(data, indent=2)orjson.dump(data, file, indent=2). From the command line:python3 -m json.tool file.json. How do I choose 2-space vs 4-space indent?
- 2 spaces is the most common choice — it is used by prettier, most linters, and VS Code defaults. 4 spaces is the Python json.tool default. For config files like tsconfig.json or package.json, 2 spaces is standard.
Can I pretty print invalid JSON?
- No. JSON must be syntactically valid before it can be formatted — the parser needs to understand the structure to add correct indentation. If your JSON is invalid, the tool reports the exact line and column of the error. Use the JSON Validator or JSON Lint tool to diagnose and fix errors first.
How do I pretty print JSON on the command line?
- Use Python's built-in json.tool:
cat file.json | python3 -m json.tool. With jq installed:cat file.json | jq .. On macOS,pbpaste | python3 -m json.toolpretty prints JSON from your clipboard directly in the terminal. Can I pretty print JSON in VS Code?
- Yes. Open a
.jsonfile in VS Code, then pressShift+Alt+F(Windows/Linux) orShift+Option+F(macOS) to format the file. VS Code uses its built-in JSON formatter which applies 2-space indentation by default. You can change the indent size in Settings → Editor: Tab Size. What is the difference between pretty print and format?
- Pretty print and format mean the same thing for JSON — both add indentation and line breaks to make compact JSON readable. "Format" is the more general term used in editors and tools; "pretty print" comes from programming language debuggers and REPLs where it means rendering a data structure in a human-readable form. They are interchangeable in the context of JSON.
Does pretty printing change the data?
- No. Pretty printing only adds whitespace — spaces, tabs, and newlines. It never changes key names, values, array order, or data types. The resulting JSON is semantically identical to the original: parsing either version produces the same JavaScript object. It is safe to pretty print any JSON without risk of altering its meaning.
Related Tools
Other free developer tools available on DevFormatter.
JSON Formatter
Format, validate, minify, and sort JSON. Detects duplicate keys and converts to YAML.
JSON Minifier
Strip all whitespace from JSON to reduce payload size for APIs and production.
JSON Lint
Detect syntax errors in JSON with exact line and column positions.
YAML Formatter
Format, validate, and convert YAML. Detects YAML 1.1 coercion risks.