HomeDeveloper ToolsJSON Formatter
{ } JSON Studio & Validator

JSON Formatter, Prettifier & Syntax Validator

Prettify, format, validate, and minify JSON strings with instant syntax error detection.

The JSON grammar in a nutshell

JSON is defined by RFC 8259 and ECMA-404, and its grammar is deliberately small. A value is an object, an array, a string, a number, true, false or null, and nothing else. Object keys must be strings, and every string must use double quotes.

Much of what is legal in JavaScript is not legal in JSON. There are no comments, no single-quoted strings, no unquoted keys, no undefined, and no NaN or Infinity. Numbers cannot have leading zeros, a leading plus sign or hexadecimal notation.

This formatter uses the browser's built-in JSON parser, so it accepts exactly what a JavaScript application calling JSON.parse would accept, and the error text it shows comes from the browser.

What formatting and minifying actually change

Formatting and minifying both parse the text into data and write it back out. Whitespace between tokens is the only thing intended to change, but the round trip has side effects worth knowing about before you paste the result back into a codebase.

On the default sample, two-space formatting produces 132 characters, four-space formatting 164, and minified output 85, about 36 percent smaller than the two-space version.

  • Large integers lose precision. JavaScript numbers are exact only up to 9,007,199,254,740,991, so 9007199254740993 comes back as 9007199254740992. Send big IDs as strings.
  • Duplicate keys collapse silently. {"a":1,"a":2} becomes {"a":2} with no warning.
  • Integer-like keys move to the front. {"b":1,"2":0,"a":3,"1":0} is rewritten as {"1":0,"2":0,"b":1,"a":3} because of how JavaScript orders object properties.
  • Numbers are normalised: 1.0 becomes 1, 1.50 becomes 1.5 and 1e3 becomes 1000. Escapes such as \u00e9 are written out as the character é.

Tracking down the most common syntax errors

Most invalid JSON comes from a short list of causes. Knowing them saves time when the error message points at a position that looks fine.

If the error mentions an unexpected token at the very first character, the input probably is not JSON at all. An HTML error page starting with a less-than sign is the classic case, often returned by a server when an API call fails. An invisible byte order mark at the start of a file produces the same kind of error.

  • Curly quotes pasted from a word processor, chat app or email instead of straight double quotes.
  • Single quotes around strings or keys copied from JavaScript or Python output.
  • Comments carried over from a JSONC or JSON5 configuration file.
  • A missing comma between two properties, often after editing a long file by hand.
  • Python's True, False and None, which must be true, false and null in JSON.

JSON Formatter & Validator: frequently asked questions

Why did a large ID number change after formatting?

The browser stores JSON numbers as 64-bit floating point values, which represent integers exactly only up to 2 to the power of 53 minus 1. Larger values are rounded to the nearest representable number. Many APIs, including Twitter's former API, send big IDs as strings for this reason.

Can JSON files contain comments?

Standard JSON cannot. Formats such as JSONC (used by VS Code settings) and JSON5 allow them, but a strict parser like the one here will reject them. If you need notes in a JSON file, add a regular property such as "_comment" instead.

What is the difference between JSON and a JavaScript object literal?

JSON is a text format with strict rules: double-quoted keys and strings, no functions, no comments and no trailing commas. A JavaScript object literal is code and allows all of those. Every valid JSON document is valid JavaScript, but not the other way round.

Does minifying JSON make API responses noticeably faster?

Less than you might expect when the server uses gzip or Brotli, because repeated whitespace compresses very well. Minifying still helps for uncompressed storage, logs and size-limited fields such as cookies or environment variables.

Should I indent JSON with 2 or 4 spaces?

It is a style choice with no effect on the data. Two spaces is common in JavaScript projects and keeps deeply nested files narrower; four spaces is common in Python and some style guides. Match whatever the rest of the repository uses so diffs stay clean.

All developer utilities & crypto