HomeText & Developer Tools › JSON Formatter, Validator & Minifier

JSON Formatter, Validator & Minifier

Paste JSON to pretty print it with 2 or 4 spaces or tabs, minify it to one line, sort keys, and get the exact line and column of any syntax error.

What counts as valid JSON

JSON (RFC 8259) is stricter than a JavaScript object literal, and most "invalid JSON" errors come from that gap. Keys must be strings in double quotes - {name: 1} and {'name': 1} are both rejected. Strings must use double quotes too. There are no trailing commas after the last element of an object or array, and no comments of any kind. Numbers cannot have a leading zero (012), a leading plus sign, or be NaN, Infinity or hex. The only literals are true, false and null; undefined, dates and functions are not JSON values. Whitespace between tokens is free, which is all pretty printing changes.

How formatting, minifying and error location work

The tool parses your input with the browser's built-in JSON.parse and re-serializes it with JSON.stringify, indented with 2 spaces, 4 spaces or a tab. Minify produces the same data with every optional space and line break removed - handy for embedding a config in an environment variable or shrinking a request body. Sort keys reorders every object's keys alphabetically at every depth, which makes two documents easy to diff. Neither operation changes any value.

When parsing fails, the browser's error message is mined for a position: Chrome and Edge report a character offset and, in recent versions, a line and column; Firefox reports line and column directly; Safari often reports nothing. If no position is available, a small built-in scanner walks the text and stops at the first character that breaks the grammar. The caret marks where the parser gave up, which is usually just after the real mistake - a missing comma is reported at the start of the next key, for example.

Stats and things to watch

After a successful parse you see the top-level type, total key count across all nested objects, how many objects and arrays it contains, and the maximum nesting depth (the top-level container is depth 1). Sizes are in UTF-8 bytes, which is what your server and network actually see; a non-ASCII character can take 2-4 bytes even though it is one character.

One JavaScript-specific caveat: numbers are IEEE 754 doubles, so integers above 9,007,199,254,740,991 (2^53 - 1) lose precision. A Twitter or Snowflake ID like 1234567890123456789 will come out as 1234567890123456800 after formatting. The tool warns when it spots a 16-digit-or-longer integer; the fix is to transport such IDs as strings. For files larger than a few megabytes, a command-line tool like jq or python -m json.tool will be faster than any browser page.

Frequently asked questions

What does "Unexpected token" mean?

The parser hit a character that cannot appear at that point in JSON. Look at the reported line and column for a single quote, a trailing comma, a comment, an unquoted key, or a smart quote pasted from a document.

Will formatting change the order of my keys?

Not unless you check Sort keys. JSON.stringify writes keys in insertion order, with one quirk inherited from JavaScript: keys that look like non-negative integers ("1", "42") are always emitted first, in numeric order.

Why did a large number change after formatting?

JavaScript stores numbers as 64-bit floats, so integers beyond 2^53 are rounded. This is a language limitation, not a bug in your data; APIs that hand out large IDs should send them as strings.

Is my JSON sent to a server?

No. Parsing and formatting run entirely in your browser, so API responses containing tokens or personal data stay on your machine.