What does "formatting" JSON mean?

JSON that comes from APIs, databases, or log files is usually minified — everything on a single line with no spaces beyond what's required. That's fine for machines, but hard to read when you're debugging. Formatting JSON (also called beautifying, pretty-printing, or indenting) adds whitespace — line breaks and indentation — to make the structure visible.

The key fact about JSON formatting: it changes only whitespace, never data. A JSON parser treats these two strings identically:

{"name":"Alice","age":30,"roles":["admin","editor"]}

{
  "name": "Alice",
  "age": 30,
  "roles": [
    "admin",
    "editor"
  ]
}

The second form takes more bytes, but both parse to the same value. Formatting is purely cosmetic — you can always convert between the two without touching the data.

When do you need to format JSON?

Most developers reach for an online formatter in these situations:

  • Debugging an API response. You made a request with curl or Postman and the response is a wall of text. Paste it into a formatter to see the structure.
  • Reading a database export. JSON stored in a database column or exported from MongoDB/DynamoDB is typically compact. Format it to understand the schema.
  • Reviewing a config file. A colleague sent you a JSON config that's hard to read in your terminal. Format it before reviewing.
  • Preparing JSON to commit. You want to normalize the indentation of a JSON file before checking it into version control.
  • Spotting a bug in a large JSON payload. An unexpected value in a deeply nested object is invisible in minified JSON but obvious when formatted.

In each case, an online formatter lets you do this without opening a code editor, installing a tool, or writing a line of code.

How to format JSON online, step by step

  1. Open the formatter. Go to json-indent.com. No account needed.
  2. Paste your JSON. Click the input panel on the left and paste your JSON (Ctrl+V / Cmd+V). Formatting runs automatically as you type.
  3. Choose an indent size. Use the dropdown in the output panel header to switch between 2 spaces, 4 spaces, or tab.
  4. Check for errors. If the JSON is invalid, the error line is highlighted in the gutter and the output panel shows the exact problem. Fix the error and the formatted output appears immediately.
  5. Copy or download. Click Copy to copy the formatted JSON to your clipboard, or Download to save it as a .json file.

Choosing an indent size

The three common choices — 2 spaces, 4 spaces, tab — produce identical data. The right choice depends on your context:

  • 2 spaces is the most common for JSON files specifically. JavaScript and Node.js communities use it by default. JSON.stringify(obj, null, 2) and VS Code's JSON formatter both default to 2 spaces. If you're unsure, choose this.
  • 4 spaces is standard in Python (PEP 8) and common in Java and C# projects. If the JSON file lives in a Python or Java repository, 4 spaces fits the surrounding code.
  • Tab is used in Go (where gofmt enforces tabs), PHP, and some JavaScript style guides. Tabs have the advantage of being visually resizable — each developer can configure their editor to show tabs as 2, 4, or 8 spaces wide.

For JSON consumed by an API or parsed by code, the indent size makes no functional difference. For JSON stored in version control and edited by humans, pick whichever matches your team's conventions and stick to it — mixing indent sizes in one file causes messy diffs.

Privacy: what happens to your data

This is worth thinking about when you're working with sensitive payloads — API responses with authentication tokens, user data, or internal configuration. The json-indent.com formatter runs entirely in your browser using JavaScript. Your JSON is never transmitted to a server. There is no backend receiving your input. You can disconnect from the internet after the page loads and the formatter continues to work.

If you need to format JSON in a fully offline context — on a secured machine with no internet access — you can use the command-line alternatives below instead.

Alternatives to an online formatter

Sometimes an online tool isn't the right fit. Here are the most useful alternatives:

VS Code

Open the JSON file in VS Code and press Shift+Alt+F (Windows/Linux) or Shift+Option+F (Mac). VS Code uses its built-in JSON formatter, which defaults to 2-space indentation.

Command line with jq

jq is the standard Unix tool for JSON. It formats with 2-space indentation by default:

cat response.json | jq '.'
# or pipe curl output directly
curl https://api.example.com/data | jq '.'

Python's json.tool module

Python ships with a built-in JSON formatter — no installation needed:

cat response.json | python3 -m json.tool
# or format a file
python3 -m json.tool data.json

In Python code

import json
data = json.loads(raw_json_string)
print(json.dumps(data, indent=2))

In JavaScript/Node.js

const data = JSON.parse(rawJsonString);
console.log(JSON.stringify(data, null, 2));

For more detail on the command-line options, see the guide on pretty-printing JSON in the terminal.

Format JSON in your browser — free

Paste any JSON into the online formatter — formats instantly, validates as you type, no signup required.

Open JSON Formatter →

Frequently Asked Questions

What does formatting JSON do?

Formatting JSON adds indentation and line breaks to make the structure visible and human-readable. The data itself is unchanged — only whitespace is added. Any JSON parser reads formatted and minified JSON identically.

Is 2-space or 4-space indentation better for JSON?

Both are valid. 2-space is the most common for JSON specifically, used by JavaScript, Node.js, and many JSON APIs. 4-space is common in Python and Java projects. Choose whichever matches your team's conventions.

Is it safe to format JSON in an online tool?

It depends on the tool. json-indent.com processes your JSON entirely in your browser using JavaScript — your data is never sent to a server. For sensitive payloads (credentials, PII, internal API responses), use a client-side tool like this one, or format using jq or Python locally.

How do I format JSON in VS Code?

Open the JSON file in VS Code and press Shift+Alt+F on Windows/Linux or Shift+Option+F on Mac. VS Code uses its built-in JSON formatter, which produces 2-space indentation by default (configurable via editor.tabSize and editor.insertSpaces in settings).

Can I format JSON with comments?

Standard JSON does not allow comments — a formatter that follows RFC 8259 will report an error if your input contains // or /* */ comments. If you're working with JSONC (used by VS Code settings, tsconfig.json) or JSON5, you need a tool that supports those formats. See the guide on JSON vs JSON5 vs JSONC.