Blogchevron_rightJSON Tools
JSON Tools

JSON Indentation Guide: 2 Spaces, 4 Spaces, or Tabs?

Indentation style is the most debated JSON formatting choice. Here is what each option offers, what major ecosystems use, and how to stop arguing and just pick one.

April 18, 2026·6 min read

2-Space Indentation

2-space indentation is the most common choice in JavaScript and Node.js ecosystems. It is the default in Prettier, npm, VS Code's built-in JSON formatter, and the Node.js documentation. The compact indentation keeps deeply nested JSON from running off the right edge of the screen.

Google's style guide, Airbnb's style guide, and most major JavaScript open-source projects use 2 spaces. For JSON files in frontend or Node.js projects, 2 spaces is the safe default that requires the least explanation.

4-Space Indentation

4-space indentation is standard in Python (PEP 8), Java, and C# codebases. Python's json module uses indent=4 in its documentation examples. The extra indentation makes each nesting level visually distinct, which is valued in languages where indentation is semantically significant (like Python).

For JSON files in Python or Java projects, 4 spaces signals consistency with the surrounding code style. When a team uses Python as the primary language, matching the JSON indentation to the Python standard avoids visual jarring when switching between file types.

Tab Indentation

Tab indentation has the advantage of being adjustable — each developer's editor can render tabs at their preferred width (2, 4, or 8 spaces) without changing the file. This matters for accessibility: some developers with visual impairments prefer wide indentation.

Tabs have fallen out of favor for JSON in most ecosystems because JSON is frequently transmitted over HTTP or included in contexts where tab width is not configurable. The practical result is that tabs look inconsistent across environments, while spaces look the same everywhere.

How to Enforce Consistency

Once your team has chosen an indentation style, automate enforcement. An .editorconfig file in the project root sets indentation for all file types and is respected by most editors. A Prettier configuration with a tabWidth setting combined with a pre-commit hook eliminates manual reformatting entirely.

The most important principle is consistency within a project. A project that uses 2 spaces throughout is better than one that uses 2 spaces in some JSON files and 4 in others. Pick a standard, configure it in tooling, and move on — the indentation size matters far less than the consistency.

Try JSON Pretty Print Free Online

No sign-up required. 100% client-side — your data never leaves your browser.

Open JSON Pretty Printarrow_forward

Frequently Asked Questions

What does Prettier use for JSON indentation by default?

Prettier uses 2 spaces by default for all file types, including JSON. This can be changed via the tabWidth setting in .prettierrc.

Does indentation affect JSON file size significantly?

In raw bytes, 4-space indentation produces files about 15-20% larger than 2-space for deeply nested JSON. GZIP compression largely eliminates this difference, since repeated whitespace compresses extremely well.

Which indentation style is required by the JSON specification?

The JSON specification (RFC 8259) does not require any indentation. Whitespace is optional in JSON; the choice of indentation is purely a human readability convention.

JSON Indentation Guide: 2 Spaces, 4 Spaces, or Tabs?