FileToolsHub logo

By FileToolsHub Editorial · Published 2026-09-27 · JSON

How to Format JSON

Pretty-print and validate JSON using editor tooling, command-line utilities, or FileToolsHub’s JSON formatter and validator.

Open JSON Formatter →

JSON is the default wire format for APIs, config files, and log exports. Minified one-line payloads are valid but hard to review; formatted JSON with indentation makes mismatched braces and typos visible before you deploy. You can beautify in VS Code, use jq or Python in a terminal, or paste into /tool/json-formatter and /tool/json-validator on FileToolsHub when you need a quick check in the browser. Reviewers appreciate when API samples in README files match the validator your CI runs—paste formatted JSON into docs after the same jq command you use in GitHub Actions. When customers email malformed JSON, reply with the validator error string instead of guessing; it shortens support threads. Large arrays belong in newline-delimited JSON files for streaming pipelines; pretty JSON is for humans, NDJSON is for bulk ingest. Configuration repos sometimes lint JSON with pre-commit hooks; align indent width with .editorconfig so teammates do not fight two-space versus tab diffs. When JSON sits inside YAML heredocs, validate the inner block separately—indentation errors there are common during Kubernetes manifest edits. OpenAPI specs embedded in repos should validate in CI with the same strict parser your runtime uses—drift between pretty docs and production causes integration surprises. When customers paste JSON into chat support, ask them to run json.tool locally before redacting secrets so you help with structure, not accidental token leaks.

What formatting means

Pretty-printing adds newlines and indentation without changing data. Keys stay quoted strings; numbers and booleans stay typed. Sorting keys is optional—some teams sort alphabetically for stable diffs, others preserve source order from the API.

VS Code and other editors

Paste JSON into a .json file in VS Code, then Format Document (Shift+Alt+F on Windows, Shift+Option+F on macOS). Install a JSON language mode if prompted. JetBrains IDEs offer Code → Reformat Code with JSON selected. Neovim users often pipe through jq from a command.

jq on macOS, Linux, and Windows

Install jq, then run jq . file.json for pretty output or echo '$MINIFIED' | jq . for a string from clipboard scripts. jq . empty file.json exits silently when JSON is valid—handy in CI. For compact output again, jq -c . file.json.

Python one-liner

python3 -m json.tool < input.json > pretty.json reads UTF-8 JSON and prints indented output. On Windows PowerShell, Get-Content raw.json | python -m json.tool works when Python is on PATH.

Validate before you format

A trailing comma, single quotes instead of double quotes, or unescaped newlines in strings makes JSON invalid. /tool/json-validator reports the error line when parsing fails. Fix validation errors first; formatting tools cannot pretty-print invalid text meaningfully.

Git diffs and code review

Format JSON once before opening a pull request so reviewers see semantic changes, not whitespace noise. For generated configs, consider compact JSON in production artifacts and pretty JSON only in dev copies. Pre-commit hooks can run jq or python -m json.tool --compact to normalize.

Unicode and escaping

JSON strings must escape control characters and quotes. Non-ASCII UTF-8 is valid in JSON strings; ensure your editor saves UTF-8 without BOM surprises. When embedding JSON inside HTML script tags, escape closing script sequences per your framework’s guidance.

FileToolsHub formatter workflow

Open /tool/json-formatter, paste minified API responses or config snippets, choose indent width if offered, and copy the result into your repo. Follow with /tool/json-validator on edited files before commit when you do not have jq in CI yet.

Final checks

API gateways and log aggregators often enforce maximum payload size—pretty JSON for debugging can be minified again with jq -c before shipping over the wire. Teams sometimes store .json.min and .json.pretty side by side in repos; document which file deploy scripts consume so CI does not upload the wrong variant.

FAQ

Is JSON5 the same as JSON? No—JSON5 allows comments and trailing commas; strict JSON parsers reject those. Why did my API client break after formatting? Pretty-printing should not change semantics; if it did, the payload was not JSON or was double-encoded.

Can I format JSON inside a string field? Outer JSON must be parsed first; inner escaped JSON needs a second pass after unescaping. Does the validator fix errors automatically? It points to problems; you edit the source, then format again.

← All guides