JSON Pretty Print: 4 Easy Ways (VS Code, Browser, Online)
The fastest way to pretty print JSON is to paste it into a formatter or trigger a format shortcut in your editor: in VS Code, press Shift+Alt+F with a .json file open; in Chrome DevTools, log the parsed object to the console; on the command line, pipe the data through jq .. Here are four methods, ranked by situation.
Why JSON Is Minified — and What Pretty Print Changes
APIs, log files, and config stores usually ship JSON as a single line. Minification removes every space, newline, and indent that humans rely on, because machines do not need them and bytes cost money: a typical minified API response is 10–30% smaller than its pretty-printed equivalent, and at millions of requests per day that difference is real bandwidth. Production endpoints return minified JSON by default for exactly this reason.
Pretty printing is the reverse operation. It re-inserts whitespace — most commonly 2 or 4 spaces per nesting level — without changing a single key or value. Here is the same 55-byte object in both forms:
{"id":7,"name":"Widget","tags":["a","b"],"active":true}
{
"id": 7,
"name": "Widget",
"tags": [
"a",
"b"
],
"active": true
}
Same data, same validity — but the second version is scannable in seconds. That matters more than it sounds. When you are hunting a syntax error, an indented document points at the failure visually: the line where indentation suddenly breaks is usually the line with the missing bracket or extra comma. In a minified blob, the same error is a needle in one giant haystack line.
| Aspect | Minified | Pretty printed | |---|---|---| | File size | Smallest (no whitespace) | 10–30% larger | | Human readability | Poor | Excellent | | Diff friendliness | One giant changed line | One changed line per edit | | Syntax errors | Hard to locate | Visually obvious | | Best for | API responses, storage, caching | Reading, editing, debugging, code review |
The rule of thumb: keep JSON minified in transit and at rest, and pretty print it the moment a human needs to look at it.
Step-by-Step: 4 Ways to Pretty Print JSON
1. VS Code — fastest for files
- Open the
.jsonfile. If your JSON is pasted into an untitled buffer, save it with a.jsonextension (or set the language mode to JSON in the bottom-right status bar) so formatting activates. - Press Shift+Alt+F on Windows and Linux, or Shift+Option+F on macOS. The whole document formats instantly with 2-space or 4-space indentation, depending on your editor settings.
- To format only a selection, highlight it first and press Ctrl+K Ctrl+F (Cmd+K Cmd+F on macOS).
If nothing happens, the JSON itself is usually broken — check the Problems panel; VS Code will flag the exact character that stopped the parser.
2. Browser DevTools — fastest for API responses
Chrome, Edge, and Firefox pretty print JSON with zero extensions:
- Open DevTools with F12 and switch to the Console tab.
- Paste the minified JSON into a variable:
const data = {"id":7,"name":"Widget"}— quotes around the whole thing are not needed if it is a valid object literal. - Type
dataand press Enter. The object expands into a collapsible tree you can navigate level by level. - Bonus: Chrome renders any URL that returns
Content-Type: application/jsonas a formatted, collapsible view natively — just open the API URL in a tab, no code required.
3. Command line — best for pipes and automation
Two tools cover almost every case. First, jq, the standard JSON processor:
curl -s https://api.example.com/data | jq .
The trailing . is the identity filter — it re-prints the input with default 2-space indentation. Save the result with jq . input.json > pretty.json.
Second, Python, which is preinstalled on macOS and most Linux systems:
python -m json.tool input.json > pretty.json
Add --indent 4 for four-space output. Both approaches work beautifully inside shell pipelines, which is where editors and browsers cannot follow.
4. Online formatter — no install, works anywhere
On a locked-down work machine, on a phone, or just doing a one-off check? Paste the JSON into a browser-based tool and click format. The free JSON formatter on Utilvy does this in one step: paste, format, copy. It validates as it formats, so a stray comma or missing quote is flagged immediately instead of silently breaking your next parse. Nothing to install, identical behavior on every operating system.
Does pretty printing change the JSON data?
No. Whitespace between tokens is not data in JSON: {"a":1} and the same object spread across five lines are byte-for-byte different but semantically identical — every parser extracts exactly the same values. The one caveat is whitespace inside string values, which is real data; a correct formatter never touches anything between quotes.
How do I pretty print JSON in Python?
Use json.dumps with the indent argument:
import json
data = json.load(open("input.json"))
print(json.dumps(data, indent=2))
Add sort_keys=True if you want alphabetical key order; otherwise Python preserves the original key order. For a quick file-to-file conversion without writing any code, the python -m json.tool command from Method 3 does the same thing in one line.
Can I minify JSON back after pretty printing?
Yes — the reverse operation simply removes whitespace again. In jq, use jq -c . for compact output. In Python, json.dumps(data, separators=(",", ":")) produces minified text. Some editor extensions add a minify command to VS Code. Always re-validate before minifying: minification does not fix errors, it only hides them.
The Bottom Line
Minified JSON is for machines; pretty JSON is for people. Pick VS Code when you are editing a file, DevTools when the data came from an API call, jq or Python when you are in a terminal, and an online tool when you cannot install anything. Next time a wall of {"a":1,"b":2 hits your screen, paste it into the JSON formatter and get readable, validated output in one click — and if that JSON carries embedded binary payloads, decode them with the Base64 encoder and decoder.