Learn how to format, pretty-print, and minify JSON payloads for readable logs, fast API transfers, and clean debugging.
Calculate your numbers instantly in your browser. Fast, free, no signup.
When APIs deliver JSON data over network connections, they typically send it minified—stripping all whitespace, newlines, and indentations to save bandwidth. While efficient for machines, reading a single 5,000-character line of compressed JSON is practically impossible for human developers.
Formatting (or "pretty-printing") JSON adds structured indentation and line breaks, transforming dense blobs into readable data trees.
The most common conventions for JSON formatting are:
The native JSON.stringify method accepts an indentation parameter as its third argument:
const raw = '{"name":"John","city":"New York","active":true}';
const parsed = JSON.parse(raw);
// Pretty-print with 2 spaces
const formatted = JSON.stringify(parsed, null, 2);
console.log(formatted);
Using Python's built-in json module:
import json
data = {"name": "John", "city": "New York", "active": True}
formatted = json.dumps(data, indent=2)
print(formatted)
jqIf you use Linux, macOS, or WSL, the powerful jq utility formats streams effortlessly:
curl -s https://api.example.com/data | jq .
When you are ready to transmit JSON payloads across networks or store them in database columns, minification removes unnecessary indentation bytes:
const minified = JSON.stringify(JSON.parse(formattedText));
This reduces network payload sizes by anywhere from 15% to 40%.
Need to inspect a messy JSON string right now without running a terminal command? Paste your text into our free JSON Formatter. You can format with 2 or 4 spaces, minify, and copy the clean output instantly without sending any data over the internet.