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.
- 1Paste your JSON
- 2Click Convert
- 3Copy the formatted, indented output (or read the error if invalid)
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.jsonor 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
- Trailing commas.
{"a":1,}is valid JavaScript but not valid JSON. - Single quotes. JSON requires double quotes around both keys and string values.
- Unquoted keys.
{name: "Ana"}is a JavaScript object literal, not JSON. - Comments. JSON has no comment syntax. Remove
//and/* */before parsing, or use a format like JSONC for config files that tolerate them. - Stray characters. A byte-order mark, a leftover
console.logprefix 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.
Related Tools
JSON Minifier
Compress JSON to its smallest valid form by removing all whitespace, using the native JSON parser.
XML Formatter
Reformat XML with proper nested indentation based on tag depth — a lightweight tag-based indenter, not a full XML parser.
HTML Formatter
Reformat HTML with proper nested indentation based on tag depth — a lightweight tag-based indenter, not a full HTML parser.