JSON Formatter & Validator

Paste JSON, then beautify, minify or validate. This tool does not upload your data.

Beautifying and minifying a pasted document

  1. Paste your text into the box. It can be a short config snippet or a long API response on a single line.
  2. Choose the indent: 2 spaces, 4 spaces or a tab.
  3. Press Beautify to spread the data over indented lines, or Minify to squeeze it onto one line with no spaces. A green "Valid JSON" message confirms the text parsed.
  4. Press "Copy result" to put the contents of the box on your clipboard, or "Clear" to start over.

The tool replaces the text in the box with the formatted version, so what you see is exactly what gets copied. If you want to keep the original, copy it somewhere else first.

The formatting runs in your browser through the built-in JSON engine, and the tool does not send your text anywhere. Even so, avoid pasting passwords, API keys or other secrets into any website; replace them with placeholders first.

In short

Beautify adds indentation and Minify removes every space that is not part of a value; the data itself stays the same. Tab is the smallest readable indent. Reformatting can change how numbers and escapes are written, and with duplicate keys only the last value is kept.

Frequently asked questions

Is my JSON sent to a server?

No. Parsing and formatting use your browser’s built-in JSON engine. The tool does not upload your text. Even so, avoid pasting passwords, API keys or other secrets into any website.

How large a file can it handle?

Files of a few megabytes usually work, but very large input may be slow on older devices. Very large files depend on your browser memory.

Do you need Base64 instead?

See the Base64 encoder and decoder.

Why does it say my JSON is invalid when my editor accepts it?

Editors and some libraries allow extras such as comments or trailing commas. This page follows the strict rules used by JSON.parse, which is what most programs and servers use when they read your data.

Our test: how much bigger does Beautify make a file, and which indent is smallest?

Four sample documents of the kinds people paste most often were minified and then pasted into the formatter in Chromium 153.0.8010.12. We pressed Minify, then Beautify with 2 spaces, 4 spaces and Tab, five times each, and measured the result in the box in bytes (UTF-8) and lines. The samples were an API response with 2,000 user records, a map line with 20,000 longitude/latitude pairs, a settings file nested 6 levels deep, and a log of 5,000 short events. Sizes below are in KB of 1,000 bytes.

Minified2 spaces4 spacesTabAPI response, 2,000 users294 KB531 KB719 KB437 KBMap line, 20,000 points456 KB1,096 KB1,656 KB816 KBConfig, 6 nesting levels239 KB576 KB872 KB428 KBLog, 5,000 events246 KB366 KB446 KB326 KB
Size of the same data, minified and beautified — chart drawn from the table below.
DocumentMinified2 spaces4 spacesTabLines when beautified
API response, 2,000 users294 KB531 KB719 KB437 KB30,036
Map line, 20,000 points456 KB1,096 KB1,656 KB816 KB80,008
Config, 6 nesting levels239 KB576 KB872 KB428 KB23,210
Log, 5,000 events246 KB366 KB446 KB326 KB25,002

What it means: 2-space Beautify made these files 1.5 to 2.4 times larger, and 4 spaces up to 3.6 times larger, because indentation repeats on every line. Tab was always the smallest readable option, 1.3 to 1.8 times the minified size. Arrays of numbers grow the most: each coordinate pair became four lines. Every run finished in under 70 ms (median of five) on our test machine, so for files of this size the choice is about readability and size, not speed.

Our test: what does reformatting change besides spaces?

We pasted 24 short inputs into the formatter in headless Chromium 157.0.8103.78, pressed Minify, and recorded the text left in the box and the message underneath. We then pressed Beautify, with 2 spaces, on the same 24 inputs. Apart from line breaks and indentation, every result and every message matched the Minify run.

InputResult in the boxWhat changed
{"a":1,"b":2,"a":3}{"a":3,"b":2}The first "a" was dropped without a warning. The surviving key kept its first position.
{"b":1,"10":2,"a":3,"2":4}{"2":4,"10":2,"b":1,"a":3}Keys that look like whole numbers moved to the front, in ascending order.
{"b":1,"01":2,"1":3}{"1":3,"b":1,"01":2}"01" kept its written order among the other keys: with a leading zero it does not count as a number key.
[1.0], [1.50], [1e2], [1E+2], [2.5e-3], [-0][1], [1.5], [100], [100], [0.0025], [0]Numbers were rewritten in their shortest form. Minus zero lost its sign.
"caf\u00e9", "a\/b", "\ud83d\ude00""café", "a/b", "😀"These escapes became the characters themselves.
"\u2028"the raw line separator characterThe escape was replaced by an invisible character.
"a\tb", "\u0001", "\ud800"unchangedTabs, control characters and a lone half of an emoji pair stayed escaped.
[0.30000000000000004]unchangedMarked "Valid JSON", with the note about numbers longer than 15 to 16 digits.
a byte order mark, then {"a":1}unchanged"Invalid JSON: Unexpected token", with no line or column.

Six more inputs came back exactly as typed: an empty key, a key named __proto__, an object holding an empty array and an empty object, and a bare string, number or null on its own.

What it means: if you format a file and then compare it with the original in a diff tool, numbers, key order and escapes can show up as changes even though the data is the same. Two cases are real changes: with duplicate keys an earlier value is lost, and minus zero becomes plain 0. The long-number note counts digits, so it also appeared for the 17-digit decimal above, a value that needed no rounding. A byte order mark is an invisible character that some Windows editors put at the start of a file. If a file that looks correct is reported as an unexpected token with no line or column, save it again as UTF-8 without a byte order mark, or delete the first character and try again.

More details

How to format JSON

  1. Paste your JSON into the box.
  2. Click Beautify to add indentation, or Minify to remove all spaces.
  3. If the JSON is invalid, the message shows the position of the first error.

Common JSON mistakes

  • Trailing commas after the last item: [1,2,]
  • Single quotes instead of double quotes: {'a':1}
  • Unquoted keys: {a:1}
  • Comments, which standard JSON does not allow

Finding the line and column of a syntax error

The page hands your text to the JavaScript engine's own JSON.parse. If parsing succeeds, the result is written back with JSON.stringify using your chosen indent. If it fails, the message "Invalid JSON:" is shown followed by the browser's own explanation. When the browser reports only a character position, the tool counts the line breaks before that position and adds a line and column, for example "(line 3, column 14)". Some browsers already include line and column in their message, in which case it is shown as is, so wording differs between Chrome, Firefox and Safari.

The reported position is where the parser gave up, which is often just after the real mistake. A missing comma between two properties is reported at the start of the second one. An unclosed string can be reported at the very end of the text. Look a little before the position.

Example: a small object before and after

Pasting {"id":7,"tags":["a","b"],"ok":true} and pressing Beautify with 2 spaces gives:

  • {
  •   "id": 7,
  •   "tags": [ followed by "a", and "b" on their own lines and a closing ],
  •   "ok": true
  • }

Pressing Minify on that result returns the original single line. Because the text is parsed and rewritten, formatting is normalized: extra spaces and line breaks disappear, and numbers are rewritten in their shortest form, so 1.0 becomes 1 and 1e2 becomes 100. Escape sequences such as \u00e9 come back as the character itself (é).

Key order, duplicate keys, big numbers and empty containers

  • Key order is preserved in the sense that properties come back in the order they were written, except that keys that look like whole numbers (such as "2" or "10") are always listed first in ascending order. This is how JavaScript objects work, not a bug.
  • Duplicate keys: if the same key appears twice in one object, the last value wins and the earlier one is silently dropped. Beautify will not warn you.
  • Big numbers lose precision. JavaScript stores numbers as 64-bit floating point, so integers above 9007199254740991 may be rounded. Long numeric IDs should be kept as strings.
  • Empty containers stay compact: [] and {} are not expanded across lines.

Reading logs, checking configs and preparing fixtures

  • Reading a minified API response or a log line that contains a JSON payload.
  • Checking a hand-edited config file before deploying it, to catch a trailing comma or a missing quote.
  • Shrinking a payload before pasting it into a command line or a test fixture.
  • Normalizing indentation so that two files can be compared line by line in a diff tool.

What counts as valid JSON here

  • Only strict JSON is accepted. Files with comments, single-quoted strings or unquoted keys (often called JSON5 or JSONC) are reported as invalid, even though many tools tolerate them.
  • The tool checks syntax, not meaning. It cannot tell you that a field is missing or has the wrong type; that requires a schema validator.
  • Multiple JSON documents pasted one after another, as in newline-delimited logs, are not valid as a whole. Format them one at a time.
  • Pressing Beautify on text that has an error leaves your input untouched, so nothing is lost.

More questions

Which indent should I choose?

Two spaces keep deeply nested data narrow; four spaces are easier to scan in shallow data; a tab lets each reader's editor choose the width. Pick whatever matches the project you are pasting into.

Does minifying change the data?

Apart from duplicate keys, where only the last value is kept, and minus zero, which becomes 0, no values change. Only whitespace outside of strings is removed, apart from the number normalization described above.

Related guides

More in Text & developer