Text UtilitiesText FormattersFree Tool

JSON Formatter

Pretty-print JSON with real 2-space indentation using the browser's native JSON parser — shows the exact parse error if your JSON is invalid.

How to Use JSON Formatter
  1. 1Paste your JSON
  2. 2Click Convert
  3. 3Copy the formatted, indented output (or read the error if invalid)
About JSON Formatter

What this JSON formatter does

This tool takes JSON text, parses it with your browser's built-in JSON.parse(), and prints it back with two-space indentation using JSON.stringify(). If the text is valid, you get a readable, consistently indented version. If it is not valid, you get the parser's own error message instead of output, which makes the tool a quick validator as well as a beautifier. Nothing is sent to a server; the parsing happens on your device.

When formatting JSON actually helps

  • Reading API responses. Most APIs return minified JSON on a single line. Indenting it lets you see nesting, spot the field you need and check array lengths at a glance.
  • Debugging config files. A misplaced comma in package.json, tsconfig.json or a CI configuration is easy to miss by eye. Pasting the file here points you at the failing position.
  • Cleaning diffs. Two JSON files that differ only in whitespace produce noisy diffs. Formatting both with the same indentation first makes the real changes obvious.
  • Sharing examples. Pasting an indented payload into a bug report or documentation is far easier for others to read than a single 4,000-character line.

A worked example

Input: {"user":{"id":42,"roles":["admin","editor"],"active":true}}

Output is the same data spread over several lines, with user indented one level, the roles array expanded one item per line, and each closing brace aligned with its opening line. The data is identical; only the whitespace changes.

Why JSON is rejected: the five usual causes

  1. Trailing commas. {"a":1,} is valid JavaScript but not valid JSON.
  2. Single quotes. JSON requires double quotes around both keys and string values.
  3. Unquoted keys. {name: "Ana"} is a JavaScript object literal, not JSON.
  4. Comments. JSON has no comment syntax. Remove // and /* */ before parsing, or use a format like JSONC for config files that tolerate them.
  5. Stray characters. A byte-order mark, a leftover console.log prefix or text copied with surrounding quotes will all fail.

Behaviours worth knowing

  • Large numbers lose precision. JavaScript stores numbers as 64-bit floats, so integers above 9,007,199,254,740,991 (253 - 1) can be silently rounded. If you handle 64-bit IDs, keep them as strings in the source data.
  • Duplicate keys. If an object repeats a key, the parser keeps the last value and the earlier ones disappear from the output.
  • Key order. Keys normally keep their original order, but JavaScript always lists integer-like keys such as "10" first, in ascending order. The output can therefore differ in order from the input for objects keyed by numbers.
  • Formatting is not schema validation. The tool checks syntax, not whether the fields match what your application expects.

Formatting versus minifying

Indented JSON is for humans; minified JSON is for transport, because removing whitespace shrinks payloads. If you need the compact form, use the JSON minifier. For XML and HTML equivalents, see the XML formatter and HTML formatter.

Privacy

Because parsing runs in your browser, you can paste internal API responses without uploading them anywhere. As a habit, still remove access tokens, passwords and personal data before sharing formatted output with other people.

Frequently Asked Questions

It parses your input with the browser's native JSON.parse(), then re-serializes it with 2-space indentation — genuine parsing and formatting, not a text-pattern trick.

It shows 'Invalid JSON:' followed by the exact error message and position the native parser reports, so you can find and fix the syntax issue.

No — this only checks and formats basic JSON syntax. For schema validation, use the JSON Schema Validator tool in Developer Tools.

No — formatting happens entirely in your browser.

Related Tools

Related Articles

More from Text Utilities