JSON Formatter

Format and validate JSON data

Format, validate and minify JSON

Paste JSON to indent it for reading, check that it is valid, or strip the whitespace to make it as small as possible. When something is wrong, you get the browser's description of the error and where parsing stopped. Your data stays in your browser, which matters when it is an API response full of tokens and customer records.

The three buttons

  • Format rewrites the JSON with two-space indentation and one value per line, so the structure is easy to follow.
  • Minify removes every space and line break outside the strings. Use it for data you send or store, where only machines read it.
  • Validate checks the syntax without changing anything.

Why JSON fails to validate

JSON is much stricter than the JavaScript it grew out of. Almost every error comes from one of these:

  • A trailing comma after the last item, as in {"a": 1,}.
  • Single quotes. Keys and strings need double quotes.
  • Keys without quotes, such as {a: 1}.
  • Comments. Neither // nor /* */ is allowed. Formats like JSON5 and the JSON-with-comments used by some editors accept them, but standard JSON does not.
  • NaN, Infinity or undefined. They are not valid JSON values; use null or a number.
  • A real line break or tab inside a string. Write it as \n or \t instead.

The error message points to where parsing stopped, and newer browsers add the line and column. The actual mistake is often just before that point, typically a missing comma at the end of the previous line.

What formatting can change

Formatting reads your JSON and writes it out again, so it can only keep what JavaScript can represent:

  • Very large integers lose precision. Whole numbers above 9,007,199,254,740,991 cannot be stored exactly. A 64-bit ID such as 12345678901234567890 comes back as 12345678901234567000. If your data has IDs this long, they belong in strings.
  • Duplicate keys collapse. If an object has the same key twice, only the last value is kept.
  • Number-like keys move to the front. Keys such as "2" and "10" are listed first, in ascending order, because of how JavaScript orders object properties. Other keys keep their order.

None of this affects ordinary data, but check before you paste a formatted file back over the original.

Formatted or minified?

Indentation is for people. On a deeply nested file it can make up a large share of the size, which is why APIs and configuration stores usually keep JSON minified. If you are going to read it, format it; if a program is going to read it, minify it.

Frequently asked questions

What does Unexpected token mean in JSON?

The parser found a character it did not expect at that position. The usual causes are a trailing comma, single quotes, an unquoted key or a comment. Look just before the position given in the error.

Does JSON allow comments?

No. Standard JSON has no comment syntax. Remove them, or use a format such as JSON5 if your tools support it.

Why did a long number change after formatting?

Integers larger than 9,007,199,254,740,991 cannot be represented exactly in JavaScript, so they are rounded. Store long IDs as strings to keep them exact.

What is the difference between JSON and a JavaScript object?

JSON is a text format with strict rules: double-quoted keys and strings, no trailing commas, no comments, and no functions or undefined values. A JavaScript object literal allows all of those.

Is my JSON uploaded?

No. Formatting, minifying and validating all happen in your browser.