HandyTools Hub
← Back to Tools

JSON Formatter

Format, validate, and beautify JSON data with syntax highlighting.

Formatted JSON will appear here...

Try it with a real API response

Format a compact API response

Input

{"name":"Ada","roles":["admin","editor"]}

Formatted result

{
  "name": "Ada",
  "roles": [
    "admin",
    "editor"
  ]
}

Formatting cannot guess your intent

The tool can show where JSON is invalid, but you must decide whether a value is text, a number, or null.

Read the JSON.parse troubleshooting guide

A JSON Formatter takes compact or messy JSON and rewrites it with consistent indentation so you can actually read the structure — then, one click later, minifies it back down for production. It also validates as it goes: instead of a vague “unexpected token” from an application log, you see the exact line and column where the document breaks. Developers use it to inspect API responses, debug webhooks, review configuration files, and prepare payloads before sending them.

How to Use

  1. Paste or type your JSON into the input panel. JavaScript-style objects (unquoted keys, single quotes) can be corrected as you go.
  2. Choose an action: Format adds indentation, Minify strips all optional whitespace, and Validate checks well-formedness without changing the text.
  3. Read the result. Valid documents appear in the output panel with syntax highlighting; invalid ones show the first error with its line and column.
  4. Copy or download the result. The copy button places the exact output on your clipboard, ready for a code editor, a request body, or a .json file.

Worked Examples

Example 1 — reading an API response. A fetch call returns one long line:

{"user":{"id":42,"name":"Ada","roles":["admin","editor"],"lastLogin":"2026-09-01T09:14:00Z"},"active":true}

Formatting expands it so the hierarchy is obvious: a top-level object with user and active, and inside user a four-key object with a roles array. In the indented form you can see at a glance that roles is an array, not a string — a distinction that is nearly invisible in the one-line version.

Example 2 — the trailing comma. A config edited by hand:

{
  "timeout": 30,
  "retries": 3,
}

Validation reports the error at the comma before the closing brace. Remove it and the document is valid. This is the single most common real-world JSON mistake, largely because JavaScript and Python both allow trailing commas.

Example 3 — shrinking a payload. Before shipping a config file or embedding JSON in a log line, minify turns a 40-line pretty-printed object into one compact line, often cutting 30–50% of the bytes with zero data loss.

How It Works

JSON has a strict, small grammar: values are objects ({}), arrays ([]), strings (double quotes only), numbers, true, false, and null. A parser reads the text left to right and builds a tree in memory; every token must fit the grammar or parsing stops at that character.

Formatting walks that tree and re-serializes it with an indent step (commonly two or four spaces) and a newline after each property or element. Minifying does the same walk but emits no optional whitespace at all. Because both operations re-serialize a parsed structure, they cannot silently change values — but they also cannot “fix” malformed input, which is why the validator reports rather than repairs.

One consequence worth remembering: since keys are stored in an object, duplicate keys collapse during parsing, and the last occurrence wins. That is standard behavior, not a bug, but it means a document with repeated keys will look different after a round trip.

Formatting Conventions Worth Standardizing

JSON itself does not care about indentation, so teams pick a convention and stick to it. Two spaces per level is the most common default in JavaScript and web tooling; four spaces appears often in Java and Python ecosystems. Some teams also sort object keys alphabetically to make diffs stable — when a new key is added, only its line changes instead of the whole block shifting. If your project uses a formatter such as Prettier or an ESLint rule, run it on JSON files too so that a pull request shows real data changes rather than whitespace churn. The formatter here follows the same idea manually: apply it, copy the result, and keep the repository consistent.

Common Mistakes and Edge Cases

  • Trailing commas. Never legal in JSON, even though JavaScript and Python allow them.
  • Single quotes or unquoted keys. {name: 'Ada'} is valid JavaScript but invalid JSON; both need double quotes.
  • Comments. // and /* */ are not part of JSON. Use a .jsonc-aware editor for configs that need them.
  • A UTF-8 BOM. Some editors save a hidden EF BB BF at the start of the file, which strict parsers reject at position zero. Re-save as UTF-8 without BOM.
  • Numbers stored as strings. "id": "007" stays a string after formatting; if a downstream system expects a number, the quote matters.
  • Very large documents. Browsers render indented text slowly beyond ~10 MB; minify first if you only need to inspect or copy.

Features

  • Format (beautify) with configurable-style indentation and syntax highlighting
  • Minify to the smallest valid representation
  • Well-formedness validation with line and column for the first error
  • Handles nested objects and arrays of any depth
  • Copy and download without leaving the browser
  • 100% client-side — data never leaves your device

Use Cases

  • API debugging: Expand an opaque response and read the fields that matter.
  • Webhook and log inspection: Find where a payload is malformed before it reaches production.
  • Configuration review: Audit a config file’s real structure instead of trusting indentation.
  • Payload preparation: Minify before embedding JSON in a request, a log line, or a URL parameter.

Frequently Asked Questions

Does formatting or minifying change my data?

No. Both operations only add or remove whitespace — indentation, line breaks, and spaces between tokens. The values themselves, including number precision and string contents, are preserved byte for byte after re-parsing. Only invalid JSON is rejected.

Why does my JSON fail with an unexpected token?

The parser stopped at the first character it could not interpret. The most common causes are a trailing comma before a closing brace or bracket, single-quoted keys or strings, comments, or an unquoted key. Paste the text into the formatter and it marks the exact line and column.

Can it repair invalid JSON automatically?

It detects and reports errors rather than guessing fixes, because silently altering a document can change its meaning. For common cases such as a trailing comma or a missing quote, the error message points at the exact spot so the fix takes seconds. For structural repairs, edit the source rather than trusting an auto-correction.

How large a JSON file can it handle?

Formatting and minifying run entirely in the browser, so the practical limit is your device's memory. Files of a few megabytes format instantly; beyond roughly 10–20 MB the browser may pause while rendering the indented output. For huge datasets, minify to inspect or split the file first.

Is the JSON I paste into the formatter sent to a server?

No. Parsing, validation, formatting, and minifying all happen locally with JavaScript in your own browser. Nothing is transmitted or logged, so the tool is safe for confidential API payloads, tokens, and internal configuration.

What is the difference between formatting and minifying?

Formatting (beautifying) expands the document with indentation and line breaks so a human can read the structure. Minifying does the opposite: it removes every optional space and line break to produce the smallest possible payload for production, storage, or network transfer. The data is identical either way.

Reviewed by the HandyTools Hub team · Last updated