Ctrl K

How to Format JSON (Beautify, Indent and Minify)

beginner TheToolSera Team 8 min read Updated 10 Jun 2026

Formatting JSON means adding indentation and line breaks so the structure becomes visible. It changes nothing about the data — only how it is laid out. This guide covers what happens under the hood, what to do when formatting fails, and how to do it safely in the browser.

What JSON formatting actually does

A formatter parses the text into an in-memory structure and then serialises it again with whitespace rules applied: one member per line, a fixed indent per nesting level, and a space after each colon. Because it round-trips through a parser, the output is guaranteed to be valid — and invalid input cannot be formatted at all.

Minifying is the same operation with the whitespace rules switched off. Formatting and minifying are lossless and fully reversible; neither adds, removes or reorders data.

Before and after

Minified (as received from an API)
{"order":{"id":"A-9931","total":249.9,"items":[{"sku":"TS-01","qty":2},{"sku":"TS-04","qty":1}],"paid":true}}
Formatted with 2-space indent
{
  "order": {
    "id": "A-9931",
    "total": 249.9,
    "items": [
      { "sku": "TS-01", "qty": 2 },
      { "sku": "TS-04", "qty": 1 }
    ],
    "paid": true
  }
}

How to format JSON online

Format JSON in your browser

No installation, no account and no upload — the work happens locally on your machine.

  1. 1

    Open the formatter

    Open the TheToolSera JSON Formatter in any modern browser.

  2. 2

    Paste your JSON

    Paste the raw text into the input pane, or drop a .json file onto it.

  3. 3

    Choose an indent

    Pick 2 spaces, 4 spaces or tabs. Two spaces is the common default for web projects.

  4. 4

    Format

    The output pane updates immediately with indented, syntax-highlighted JSON.

  5. 5

    Fix any error

    If the input is invalid, the line and column of the first problem is reported. Correct it and formatting resumes.

  6. 6

    Copy or download

    Copy the result to your clipboard, or download it as a .json file.

JSON Formatter

Format, minify, sort keys and fold nested nodes — everything runs client-side.

Try JSON Formatter

Choosing an indent width

IndentBest forTrade-off
2 spacesWeb projects, package.json, most style guidesDeep nesting stays readable
4 spacesConfig reviewed by humans, printed documentationWide structures wrap on narrow screens
TabsTeams that let each developer set their own widthRendering varies between tools
MinifiedNetwork payloads, storage, cachingUnreadable without a formatter

Formatting in an editor or terminal

Command-line alternatives
# Python (no dependencies)
python -m json.tool input.json > pretty.json

# jq
jq . input.json > pretty.json

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

In VS Code, Shift+Alt+F (Shift+Option+F on macOS) formats the open JSON document. Prettier applies the same rules on save across a whole repository.

Why formatting fails

A formatter refuses to work on invalid JSON, which is genuinely useful — the failure tells you the file is broken. These are the causes you will hit most often:

Trailing comma

A comma after the last member of an object or array. Remove it.

Single quotes

'name' must be "name". JSON only accepts double quotes.

Unquoted keys

{ name: "Ada" } is a JavaScript literal, not JSON.

Copied console output

Browser consoles print previews with ellipses and object placeholders. Copy the raw response body instead.

Concatenated documents

Two objects pasted back to back need to be wrapped in an array, or split into separate lines (NDJSON).

If a formatter silently "fixes" your input, check what it changed. Repairing malformed JSON is a different operation from formatting, and it can guess wrong on ambiguous input.

Best practices

  • Commit formatted JSON to version control — diffs become line-level and reviewable
  • Serve minified JSON in production and let clients format it for display
  • Sort keys before diffing two documents so ordering noise disappears
  • Never paste secrets, tokens or customer data into an online tool that uploads to a server

That last point is why every TheToolSera tool runs entirely in the browser tab: your JSON is parsed by your own machine and never sent anywhere.

Frequently asked questions

Does formatting JSON change the data?

No. Only whitespace changes. Keys, values, types and array order are identical before and after.

How do I format JSON without uploading it?

Use a browser-based formatter that parses locally. TheToolSera JSON Formatter never transmits your input — it is processed in the page itself.

What is the difference between beautify and minify?

Beautify adds indentation and newlines for humans; minify strips all optional whitespace for machines. Both produce equivalent data.

Can I format a very large JSON file in the browser?

Yes, up to the memory available to the tab. Files of a few hundred megabytes are usually better handled with jq on the command line.

Put this into practice

JSON Formatter runs entirely in your browser — no upload, no account, no limits.

Open JSON Formatter

Related tools

Related guides

All guides

Explore related topics