JSON Formatting & Indentation: Tabs vs Spaces Best Practices
2024-06-14
Formatting is not just aesthetics—consistent indentation improves reviews and reduces merge noise. Here is how to choose and when to compress.
Whitespace in the JSON spec
Spaces and newlines are insignificant to parsers; style is a human and team concern.
Tabs vs spaces
Prefer spaces for cross-editor consistency and cleaner diffs. Tabs are legal but rarely used in public JSON examples.
2 vs 4 spaces
Two spaces dominate front-end and Node ecosystems; four appears in some Java/Python configs. Pick one per repo.
{
"user": {
"name": "Alice",
"roles": ["admin", "editor"]
}
}When to pretty-print
Debugging, documentation, and manual edits—format before review so diffs show real changes.
When to minify
Production transport and storage size. Keep a readable source elsewhere; do not hand-edit minified JSON.
Team tips
Use .editorconfig for json files. Optional CI parse check. Document examples with 2 spaces; logs may stay minified.