tomai
Free · Developer Tools

JSON Formatter

Format, validate, minify and sort JSON — 100% in your browser

Input
Output

Technical details worth knowing

JSON is defined by RFC 8259, and three corners of that spec bite people in real projects:

  • Numbers are IEEE-754 double-precision floats — integers beyond 2⁵³ (e.g. 9007199254740993) silently lose precision in any JavaScript-based parser, which is why IDs from APIs often arrive as strings.
  • Duplicate keys are not forbidden by the spec; parsers commonly keep the last occurrence, and this formatter does the same.
  • Validation reports the first syntax error with its exact line and column, then stops — fix it, run again, meet the next one if there is one.

What Is a JSON Formatter?

A JSON formatter takes raw JSON, often a single cramped line copied from an API response, a config file or a log stream, and re-lays it as indented structure a human can scan. This tool formats with selectable indentation, minifies back to a compact single line, validates without changing anything, optionally sorts object keys recursively, and reports byte size, total key count and nesting depth after every run. Because parsing, printing and statistics all execute inside the browser, production payloads and secret-bearing configs can be pasted without shipping them to a server.

From one-line API soup to readable structure

  • Beautify with 2-space, 4-space or Tab indentation, or minify to the tightest valid single line
  • Validate-only mode that checks syntax and leaves the text untouched
  • Recursive key sorting that orders every nested object alphabetically before printing
  • Error reports carrying the parser message plus the exact line and column of the failure
  • Post-run statistics for byte size, key totals and maximum depth, with copy and JSON file download

Debugging sessions where it pays off

  • Reading a nested API response before writing client code against its fields
  • Tidying a sprawling config file, then minifying a payload to fit a size-limited request
  • Auditing log-extracted structures where one missing comma hides among hundreds of lines

Big payloads and duplicate-key surprises

Parsing follows strict JSON, so trailing commas, comments and single-quoted strings are rejected. Duplicate object keys keep the last value per the JSON standard, which can surprise anyone expecting an error, and very deep or large documents may take a noticeable moment since statistics walk the entire tree. An empty box is refused outright, because there is nothing to validate.

Privacy: nothing you paste ever leaves the browser tab; formatting and validation are strictly local, so sensitive payloads stay exactly where you put them.

Last updated · 2026-09-01

📚 Common JSON errors and how to fix them

Eight errors cause almost every failed JSON parse. Find yours in the table, fix the line the formatter highlights.

MessageCauseFix
Unexpected token <Response is HTML, not JSONCheck the endpoint; you are parsing an error page
Unexpected end of inputMissing closing brace/bracketUse the formatter's indent guide to find the unclosed block
Unexpected stringMissing comma between elementsAdd the comma the validator points to
Unexpected token ' in JSONSingle quotes usedJSON requires double quotes — swap them all
Unexpected token ,Trailing comma before } or ]Remove the last comma
Unexpected numberLeading zeros (007) or hex (0x1F)Quote the value as a string or drop the prefix
Duplicate keySame key twice — last one silently winsRename one; duplicate keys are legal but dangerous
Invisible garbageBOM or copy-paste whitespaceRe-paste from a plain-text source

Two extras worth knowing: JSON has no comment syntax (JSONC adds one — VS Code settings use it), and numbers have no leading-zero or hex forms. Everything here runs locally in your browser — not sure JSON is the right format at all? Read the format comparison.

Last updated · 2026-09-01

Why use this instead of an editor plugin

🧭

Format, sort, and measure

Beautify raw JSON with two-space, four-space, or tab indentation, toggle deep key sorting, and read byte count, key count, and nesting depth from the status line after every run.

🎯

Errors with exact positions

Validation reports the precise line and column of the first syntax error, so a missing comma deep inside a nested object points straight at the fix instead of ending in a generic parse failure.

📦

Minify, copy, or download

Minify collapses the same document to a single line for tight payloads, then copy it or save it as formatted.json.

Frequently asked questions

Is my JSON uploaded to a server?

No. Formatting, validation and minification run entirely in your browser with JavaScript. Your data never leaves your device, which makes this tool safe for API keys, customer data and other sensitive payloads.

How do I find syntax errors in JSON?

Click Validate (or Format). If the JSON is invalid, we show the parser message plus the exact line and column of the first error, so you can jump straight to the problem — trailing commas, single quotes and unquoted keys are the most common causes.

What does “Sort keys” do?

It recursively sorts every object’s keys alphabetically before output. Sorted JSON is easier to diff in code review and produces stable output for caching and hashing.

Why does a long ID change its last digits after formatting?

It does not change because of formatting — it changes when the text is parsed into a JavaScript number. Anything past 2⁵³ ≈ 9×10¹µ exceeds double-precision mantissa, so trailing digits get rounded. Keep such values quoted as strings in your JSON.

Related tools

Related tools