JSON generated by machines is compact and hard for humans to read. Proper formatting adds indentation and line breaks that reveal the structure of objects and arrays at a glance. This guide covers every formatting rule you need to know, with practical before-and-after examples.
What JSON formatting actually does
Formatting (also called pretty-printing or beautifying) parses your JSON and re-prints it with consistent indentation. It does not change your data. The key below is identical to the minified version — only the whitespace is different:
// Minified (machine output)
{"user":{"name":"Jane","age":28,"roles":["admin","editor"]},"active":true}
// Formatted (human readable)
{
"user": {
"name": "Jane",
"age": 28,
"roles": [
"admin",
"editor"
]
},
"active": true
}
The four core formatting rules
1. Always use double quotes
Keys and string values in JSON must use double quotes. Single quotes are invalid and will cause a parse error in every JSON parser.
// Valid
{ "name": "Alice" }
// Invalid — single quotes are not allowed
{ 'name': 'Alice' }
2. Separate properties with commas
Every property in an object and every element in an array must be separated by a comma — except the last one. A trailing comma after the final item is not allowed in standard JSON.
// Valid
{
"first": "Alice",
"last": "Smith"
}
// Invalid — trailing comma after last property
{
"first": "Alice",
"last": "Smith",
}
3. Use consistent indentation
Two spaces is the most common standard. Four spaces is also widely used. What matters is consistency — pick one and stick to it throughout the file. Mixing two and four spaces in the same file is a common mistake when editing JSON manually.
4. Keep nesting clear
Each level of nesting should increase the indentation by one unit. Opening braces { and brackets [ go on the same line as the key. Closing braces and brackets go on their own line, aligned with the key that opened them.
{
"server": {
"host": "localhost",
"port": 8080,
"options": {
"timeout": 30,
"retries": 3
}
}
}
Common formatting mistakes to avoid
- Numbers as strings —
"count": "42"stores a string, not a number. Use"count": 42without quotes for numeric values. - Comments — JSON does not support comments.
// this is a commentwill cause a parse error. Use a field like"_comment"if you need to annotate. - Undefined or NaN — These JavaScript values are not valid JSON. Use
nullinstead. - Unescaped special characters — Newlines, tabs, and quotation marks inside strings must be escaped:
\n,\t,\".
When to format vs when to minify
Format JSON when you are reading, debugging, or editing it. Minify JSON when you are sending it over a network or storing it in production where file size matters. You can always format minified JSON again — the data is identical.
A good workflow: validate first to catch errors, then format for review, then minify before deployment.
FAQ
How many spaces should I use to indent JSON?
Two spaces is the most widely used standard. Four spaces is also common. The important thing is to be consistent throughout the file.
Can I format minified JSON?
Yes. Paste any minified JSON into a formatter and click Format. The tool parses the JSON and re-prints it with proper indentation and line breaks.
Does formatting JSON change the data?
No. Formatting only changes whitespace. The actual keys, values, and structure are identical before and after formatting.
Format JSON instantly
Paste any JSON — minified, broken, or API response — and get clean, readable output in one click. No signup, works in your browser.
Open JSON Formatter