JSON Viewer & Formatter Open the tool
JSON ViewerJSON Formatter

Online JSON Formatter

Turn a single unreadable line of JSON into properly indented, syntax-highlighted text — with your choice of 2 spaces, 4 spaces or tabs. The formatter validates as it goes, so a broken payload tells you which line to fix instead of failing silently. Everything happens in your browser; nothing is uploaded.

Format JSON now →

What a JSON formatter does

A JSON formatter re-inserts the line breaks and indentation that a minified payload leaves out. The data is untouched — only the whitespace between tokens changes — so the formatted output parses to exactly the same object. What you gain is the ability to see the shape: which keys sit at the top level, how deep the nesting goes, where an array of objects begins.

Before — one line, 118 bytes
{"order":9001,"customer":{"id":7,"name":"Ada Lovelace"},"items":[{"sku":"A1","qty":2}],"paid":true,"note":null}
After — formatted with 2 spaces
{
  "order": 9001,
  "customer": {
    "id": 7,
    "name": "Ada Lovelace"
  },
  "items": [
    {
      "sku": "A1",
      "qty": 2
    }
  ],
  "paid": true,
  "note": null
}

Because formatting requires parsing, a formatter doubles as a validator. If the text cannot be parsed it cannot be indented — which is why this tool reports the failing line and column rather than returning an empty box.

How to format JSON

  1. Paste the JSONOpen the JSON viewer and paste your JSON into the input panel, or drop a .json file onto the page.
  2. Pick an indentationChoose 2 spaces, 4 spaces or a tab in the Indent selector at the top of the input panel.
  3. Click FormatPress Format or CtrlEnter. The JSON is re-indented in place and validated at the same time.
  4. Copy or downloadUse Copy to put the formatted JSON on your clipboard, or Download to save it as a .json file.

2 spaces, 4 spaces or tabs?

There is no standard — RFC 8259 says nothing about whitespace — but the ecosystem has strong conventions, and matching them keeps your diffs quiet.

StyleUsed byBest for
2 spaces npm (package.json), Prettier, ESLint, most JS tooling The safe default. Deep nesting stays on screen.
4 spaces Python's json.tool, many .NET and Java toolchains Shallow config files where clarity beats width.
Tab Go's json.MarshalIndent examples, some editors Letting each reader pick their own visual width; smallest file size.

If the file is checked into a repository, the correct answer is simply "whatever the repository already uses". Reformatting a committed package.json from 2 to 4 spaces produces a diff that touches every line and hides the one change that mattered.

Formatting JSON in an editor or terminal

A browser tool is fastest for a payload you just copied out of a network tab. For files you already have locally, these are the usual equivalents.

Command line

# Python — built in, everywhere
python3 -m json.tool --indent 2 in.json out.json

# jq — the standard JSON CLI
jq '.' in.json > out.json
jq --tab '.' in.json      # tab indentation

# Node.js — no dependencies
node -e 'console.log(JSON.stringify(require("./in.json"), null, 2))'

In code

// JavaScript / TypeScript
JSON.stringify(value, null, 2);

# Python
json.dumps(value, indent=2, ensure_ascii=False)
// Go
b, _ := json.MarshalIndent(value, "", "  ")

VS Code

Open the file, make sure the language mode is JSON, then press ShiftAltF (ShiftOptionF on macOS). The indent width comes from editor.tabSize.

Each of these needs the file on disk and a working toolchain. When you have neither — a payload pasted from a chat message, a colleague's laptop, a locked-down machine — the browser formatter is the one that always works.

Sorting keys for clean diffs

JSON objects are unordered by definition, so two files can hold identical data and still produce a hundred-line diff purely because the keys were serialised in a different order. Enabling Sort keys before formatting normalises both sides alphabetically, and the diff collapses to the lines that genuinely changed.

This is worth doing before committing generated files — lock files, exported settings, API snapshots used as test fixtures. It is worth not doing when key order carries meaning for a human reader, as with an ordered list of pipeline stages expressed as an object.

Frequently asked questions

What does a JSON formatter do?

A JSON formatter re-inserts the line breaks and indentation that a minified payload leaves out. The data is untouched — only the whitespace between tokens changes — so the formatted output parses to exactly the same object.

Should I use 2 spaces, 4 spaces or tabs for JSON?

Two spaces is the de facto default: it is what npm writes into package.json, what most linters expect, and it keeps deeply nested documents from running off the screen. Four spaces suits shallow config files, and tabs are useful when readers need to control the visual width themselves.

Does formatting JSON change the data?

No. Formatting only adds whitespace. The one thing to be aware of is that JSON objects are unordered by definition, so if you enable Sort keys the key order in the text will change even though the data is still equivalent.

Can I format invalid JSON?

No formatter can indent text it cannot parse. When the input is malformed the validator reports the reason and the exact line and column so you can repair it first — the most common causes are trailing commas, single quotes and comments.

Is the online JSON formatter safe for private data?

Yes. This formatter runs entirely as JavaScript in your browser and makes no network request with your content, so tokens, customer data and internal API responses never leave your machine.