Machine-generated JSON is compact and hard to read. Pretty printing — also called formatting or beautifying — adds indentation and line breaks that reveal the structure. Here are the fastest methods for every environment.
In the browser — the fastest option for one-off inspection
If you have a JSON blob from an API response or a log file and need to read it right now, paste it into the JSON Formatter. It formats the JSON instantly with a collapsible tree view and 2-space indentation. No setup, no install — works entirely in your browser.
In JavaScript — JSON.stringify with the space parameter
JSON.stringify(value, replacer, space) — the third argument controls indentation:
const data = {
name: "Alice",
age: 28,
roles: ["admin", "editor"],
address: { city: "London", country: "UK" }
};
// 2-space indent (most common)
console.log(JSON.stringify(data, null, 2));
// 4-space indent
console.log(JSON.stringify(data, null, 4));
// Tab indent
console.log(JSON.stringify(data, null, '\t'));
Pass null as the second argument to include all keys. See the full guide on JSON.stringify indent options for more on the replacer parameter.
In Python — json.dumps with indent
import json
data = {"name": "Alice", "age": 28, "roles": ["admin", "editor"]}
# 2-space indent
print(json.dumps(data, indent=2))
# Sorted keys + 2-space indent
print(json.dumps(data, indent=2, sort_keys=True))
For more Python-specific options including file reformatting, see How to Format JSON in Python.
In curl — pipe to python -m json.tool or jq
The quickest way to pretty-print an API response directly in your terminal:
# Using Python's built-in json.tool (no extra install required) curl -s https://api.example.com/users | python -m json.tool # Using jq (if installed — more powerful, colorised output) curl -s https://api.example.com/users | jq '.' # Format and save to file curl -s https://api.example.com/users | python -m json.tool > users-formatted.json
In Node.js
const https = require('https');
https.get('https://api.example.com/data', (res) => {
let body = '';
res.on('data', chunk => body += chunk);
res.on('end', () => {
const data = JSON.parse(body);
// Pretty-print to console
console.log(JSON.stringify(data, null, 2));
});
});
In VS Code
Open a .json file and press Shift+Alt+F (Windows/Linux) or Shift+Option+F (Mac) to format the document using VS Code's built-in JSON formatter. This respects your editor's indentation settings.
When to pretty-print vs when to minify
Pretty print during development, debugging, and code review — it makes structures clear at a glance. Minify for production payloads where bandwidth matters. Use the JSON Minifier to strip all whitespace before shipping JSON over the network.