JSON formatter

Pretty-print or minify JSON.

An API returns one long line of JSON and you cannot tell where one object ends and the next begins. Or you have the opposite problem: a config field expects everything on a single line. This tool re-indents JSON, collapses it, and tells you straight away whether it parses at all.

How it works

What each button does

ButtonResult
Format (indent 2)Expands the data with two spaces per level — the most common style
Indent 4The same, with four spaces; easier to follow when nesting runs deep
MinifyStrips every space and line break down to a single line

Copy result puts the output on your clipboard.

Validation happens first

Every button parses the input before printing anything. Valid input shows a "Valid JSON" note; invalid input shows the parser's own error message, which usually names the position where it gave up — a useful hint for narrowing down the broken line.

Mistakes that trip the parser

InputWhy it fails
{'a': 1}Single quotes are not allowed; JSON uses double quotes
{"a": 1,}A trailing comma after the last item is invalid
{a: 1}Keys must be quoted too
// noteJSON has no comment syntax

Key order is preserved exactly as you typed it — nothing is sorted, and no values are changed. Your text stays in the browser and is not uploaded, but treat access tokens and personal data with the usual care on a shared machine.

Terms explained

JSON
A text format that stores data as key/value pairs. The standard for API responses and config files.
Indent
Leading spaces that reveal the nesting level. Two or four spaces are the usual conventions.
Minify
Removing optional whitespace so the payload is smaller to transmit or store.
Parse
Reading a string according to a grammar and turning it into a data structure.
Trailing comma
A comma left after the final item in an object or array. Legal in JavaScript, an error in JSON.

Frequently asked questions

What does "Unexpected token" mean?

The parser hit a character that cannot appear where it found it. Single quotes, trailing commas, unquoted keys and comments cause most of these. The message usually includes a position number — start reading a few characters before it.

Why is JSON with comments rejected?

The JSON standard has no comment syntax. JSONC and JSON5 are separate formats that allow them, and a standard parser refuses both. Remove the comment lines before checking here.

Does it sort the keys alphabetically?

No. The original order is kept. Only whitespace and line breaks change; the data itself, including key order, is left untouched.

Is my data sent to a server?

No. Parsing and formatting happen in your browser, so nothing leaves the page. The text is still visible on screen, so avoid pasting credentials on a shared computer.

Some numbers look slightly different after formatting

Very large integers and long decimals can exceed the precision JavaScript numbers hold, so they may come back rounded. If exact precision matters, compare the result against the original.