How to Format JSON: A Practical Guide
Dev Nexus4 min read
Turn a wall of minified JSON into something you can actually read — and validate it in the same pass.
JSON (JavaScript Object Notation) is the lingua franca of modern APIs, config files and logs. It's easy for machines to parse, but the version machines like best — a single unbroken line with no spaces — is miserable for humans to read.
Formatting (also called beautifying or pretty-printing) adds consistent indentation and line breaks so the structure becomes obvious at a glance. This guide covers how to do it properly, when to minify instead, and how to catch errors while you're at it.
The Problem
You paste an API response into your editor and get something like this:
{"id":42,"user":{"name":"Ada","roles":["admin","dev"]},"active":true,"meta":{"createdAt":"2026-01-02T10:00:00Z","tags":[]}}
For anything beyond a couple of keys, this is unreadable. You can't tell how deeply nested a value is, where one object ends and the next begins, or whether a bracket is missing. Debugging a payload in this state means counting braces by hand — and one misplaced comma will send you hunting for minutes.
The Solution
The fix is to run the JSON through a formatter that re-indents it into a clean, hierarchical layout:
{
"id": 42,
"user": {
"name": "Ada",
"roles": ["admin", "dev"]
},
"active": true,
"meta": {
"createdAt": "2026-01-02T10:00:00Z",
"tags": []
}
}
Now the nesting is visible, each key sits on its own line, and any structural problem jumps out. A good formatter also validates as it goes: if the input isn't valid JSON, it tells you where it broke instead of silently producing garbage.
The JSON Formatter does exactly this in your browser — nothing is uploaded, so it's safe for sensitive payloads.
Step-by-Step Guide
- 1
Copy your raw JSON
Grab the JSON from wherever it lives — an API response, a log line, a config file or a clipboard snippet. It doesn't matter whether it's minified or already partially indented.
- 2
Paste it into the formatter
Open the JSON Formatter and paste the text into the input. Parsing happens locally in your browser, so even production data never leaves your machine.
- 3
Click Beautify
The tool re-indents the whole document with a standard undefined-space indent and puts every key on its own line. Arrays of primitives stay compact; nested objects expand.
- 4
Read the validation result
If the JSON is valid, you'll see the formatted output. If not, you'll get an error message pointing at the problem — a trailing comma, an unquoted key or a bad escape — so you can fix it fast.
- 5
Copy the result (or minify for transport)
Copy the beautified JSON back into your editor. If you instead need the smallest possible payload — say, to embed in a URL or store in a cache — use Minify to strip all whitespace.
Common Mistakes
Confusing JSON with a JavaScript object literal
JSON is stricter than JS. Keys must be double-quoted, strings can't use single quotes, and trailing commas are illegal. Code that pastes fine into a
.jsfile may not be valid JSON.Leaving a trailing comma
{ "a": 1, }is valid JavaScript but invalid JSON. This is the single most common cause of parse errors — the formatter will flag it immediately.Formatting to hand-edit, then shipping the pretty version
Whitespace is fine for humans but wastes bytes over the wire. Beautify to read and debug; minify before sending JSON in a request body, query string or cache key.
Trusting a server-side formatter with secrets
Many online formatters upload your input to a server. If your JSON contains tokens or personal data, use a tool that formats entirely in the browser.
Frequently Asked Questions
What's the difference between formatting and validating JSON?
Formatting re-indents JSON so it's readable; validating checks that it's syntactically correct. A good formatter does both at once — it has to parse (validate) the input before it can pretty-print it. See JSON Validator vs Formatter for a deeper comparison.
What indentation should I use — 2 or 4 spaces?
Two spaces is the most common convention and keeps deeply nested JSON from drifting off the right edge. Four spaces is also fine; pick one and stay consistent. Tabs work too but render differently across tools.
Does formatting change my data?
No. Formatting only changes whitespace — the keys, values, types and order are all preserved. Minifying and beautifying are lossless round-trips of the same document.
Is it safe to paste sensitive JSON into an online formatter?
Only if the tool runs in your browser. The Dev Nexus JSON Formatter parses and formats locally with no upload, so tokens and personal data never leave your machine. Avoid formatters that send your input to a server.
Try the Tool
JSON Formatter
Beautify, minify and validate JSON instantly — right in your browser.
Related Tools
Related Articles
JSON Validator vs Formatter: What's the Difference?
They sound interchangeable, but a validator and a formatter answer two different questions about your JSON.
Read articleJSON Compare Explained: How to Diff Two JSON Objects
A line-by-line text diff lies about JSON. Here's how a structural compare finds what actually changed.
Read article