Json To Csv LogoJson To Csv

How to Format JSON: 3 Reliable Ways to Pretty-Print and Validate (2026 Guide)

Three reliable ways to make unreadable JSON readable: a free online formatter, your editor’s built-in formatter, or a one-line terminal command — with validation and the most common syntax errors fixed along the way.

Updated: 2026-10-037 min read

What “formatting JSON” actually does

JSON from an API or a log file is often minified: the entire document squeezed onto one line with no spaces. It is still valid JSON, just unreadable. Formatting (also called pretty-printing or beautifying) expands it back onto indented lines so you can see the structure: objects nested in objects, arrays of items, and where each one ends.

The word is sometimes confused with validating, and the two usually travel together. Validation answers “is this legal JSON?”, formatting answers “can a human read it?”. Good formatters do both in one pass: if your JSON has a syntax error, the formatter stops and points at the line instead of silently producing garbage.

Method 1: Free online formatter (fastest)

For a one-off conversion, an online formatter is the fastest route — no installs, no code. Prefer one that runs entirely in your browser (client-side) so your data never leaves your device; this matters if the JSON contains tokens, emails, or anything sensitive.

  • Paste your JSON into the formatter (or drop a .json file).
  • Hit Format: the tool indents the document, colors the syntax, and flags any errors with a line number.
  • Copy the formatted output back into your editor, or use the Minify button if you need the compact version for production.

Method 2: Your code editor (daily habit)

If you touch JSON regularly, formatting inside your editor is one keystroke. In VS Code, open the .json file and press Shift+Alt+F (Windows/Linux) or Shift+Option+F (Mac) — “Format Document”. VS Code can also format on save if you enable Editor: Format On Save.

Most editors need a plugin for advanced JSON work, but basic formatting is built into VS Code, Sublime Text (via packages), and JetBrains IDEs out of the box.

Method 3: Terminal command (repeatable)

When the JSON lives in a file and you want the same result every time — in a script, a deploy step, or just quickly at the command line — a one-liner beats clicking around.

Terminal
# Pretty-print data.json to the terminal
python3 -m json.tool data.json

# Write the formatted version to a new file
python3 -m json.tool data.json > data.pretty.json

# Same idea with jq, if you have it installed
jq . data.json

python3 -m json.tool also validates: it exits with an error and a line number when the file is not valid JSON, which makes it a quick gate in scripts.

Pretty-print vs minified: when to use which

Pretty-printed JSON is for humans: debugging, config files you edit by hand, examples in documentation. Minified JSON is for machines: API responses, files shipped to production, anything where bytes and parse speed matter.

Convert between the two freely — it is the same data either way. Just never hand-edit the minified version; expand it first, make your change, then minify again if the consumer needs it compact.

Common errors that formatting reveals

Nine times out of ten, a formatter “failing” is the most useful thing it can do. These are the culprits it keeps finding:

  • Trailing commas — {"a": 1,} is illegal in JSON (fine in JavaScript). Delete the comma before the closing bracket.
  • Single quotes — JSON strings need double quotes. Replace 'value' with "value".
  • Comments — // and /* */ are not part of JSON. Strip them, or switch the file to JSONC/JSON5 if your tool supports it.
  • Unquoted keys — {name: "x"} needs {"name": "x"}.
  • Copy-paste damage — smart quotes from chat apps and docs (“ ”) are not valid quote characters; replace them with straight quotes.

Next step: turn formatted JSON into a spreadsheet

Once your JSON is readable and valid, the next move is often getting it into a spreadsheet — and that is exactly what our free converter does: it flattens your JSON into clean, spreadsheet-ready CSV in seconds, with the same no-upload privacy.

Read: How to Convert JSON to CSV

Related guides

Frequently asked questions

Is formatting the same as validating JSON?

No, but they overlap. Validation checks whether your JSON follows the syntax rules; formatting rewrites it with indentation and line breaks so humans can read it. Most formatters validate first — they will not format a document with a syntax error, which is why a failed format usually means invalid JSON.

Will formatting change my data?

No. Formatting only changes whitespace: indentation, line breaks, and spaces. Keys, values, order, and types stay exactly the same — unless you explicitly turn on extras like key sorting, which some tools offer as a separate option.

What does “Unexpected token” mean when I format JSON?

It means the parser hit a character it cannot place — almost always a trailing comma, a single-quoted string, an unquoted key, or a smart quote pasted from a chat app. The error message usually includes a position; fix that spot, format again, and the next error (if any) will show up.

Can I format JSON without installing anything?

Yes. Use a free online formatter that runs in your browser, or the one-liner python3 -m json.tool if Python is already on your machine. VS Code also formats .json files out of the box with Shift+Alt+F.

Is it safe to paste JSON into an online formatter?

Usually, but pick a formatter that processes everything in your browser (client-side) — then nothing is uploaded anywhere. If the JSON contains API keys, personal data, or anything you would not email, use your editor or the terminal command instead.

What is minified JSON?

JSON with all unnecessary whitespace removed: the whole document on one line. APIs and production files use it because it is smaller and parses slightly faster. It is valid JSON — just not meant for human eyes. Any formatter can expand it back to the readable version.

Does formatting work on huge JSON files?

Yes, with limits. Browser-based formatters handle a few megabytes fine; beyond that they can freeze the tab — format locally with python3 -m json.tool or jq instead, which stream through large files without breaking a sweat.

JSON formatted and ready?

Turn that clean JSON into a spreadsheet-ready CSV in seconds — free, private, no sign-up.

Open the JSON to CSV converter
All guides