Tools › Developer › JSON formatter

JSON formatter and validator

Format, minify and check JSON, with errors that point at the character that broke it, and large numbers that survive the trip unchanged.

  • Re-prints from your source text, so a 20-digit ID is not silently rounded
  • Errors name the line and column, not just "unexpected token"
  • Minify as well as format, for when the file is going over a wire
  • Nothing is uploaded, paste an API response with real customer data in it

Why it re-prints from your text

The obvious way to format JSON is JSON.stringify(JSON.parse(text), null, 2), and it is quietly wrong. JavaScript numbers are doubles, so any integer past 2^53 loses precision on the way through: {"id": 12345678901234567890} comes back as 12345678901234567000.

That is not a rounding you would notice reading it, and it is a different record. Twitter IDs, Snowflake IDs, many database keys and most financial identifiers are past that boundary. So this formatter reads your source and re-prints it, character by character: the digits you pasted are the digits you get back.

Errors that say where

"Unexpected token in JSON at position 4721" tells you almost nothing about a file you are scrolling through. A line and column tells you where to look, and the surrounding text tells you what is wrong.

The four that account for nearly every failure: a trailing comma before a closing brace, single quotes instead of double, an unquoted key, and a comment. All four are legal JavaScript and none of them are legal JSON, which is why they are so easy to write.

Formatted, or minified

Indented for reading and editing. Minified for anything going over a network or into a field with a size limit: removing whitespace typically takes 15–30% off, and more from deeply nested structures.

Neither changes the data. A minified file and a formatted one parse to exactly the same thing, so it is safe to move between them as often as you like.

Why local matters for this one especially

JSON you need to read is usually an API response, and an API response usually has somebody's data in it: an email address, an order, a token. Pasting that into an online formatter sends it to a server whose logs you cannot see.

Nothing here leaves the tab. That is not a nicety for this tool; it is the difference between a safe habit and one that will eventually put a customer record somewhere it should not be.

Questions

Is my JSON uploaded?

No. It is parsed and formatted in this tab. Nothing is sent anywhere, which is what makes it safe to paste a real API response.

Why are big numbers not rounded here?

Because the output is re-printed from your source text rather than round-tripped through JavaScript numbers, which lose precision past 2^53.

What are the most common JSON errors?

A trailing comma, single quotes, an unquoted key, and a comment. All four are valid JavaScript and none are valid JSON.

Does minifying change the data?

No. Only whitespace is removed, so it parses to exactly the same thing.

Can it handle a very large file?

Yes. There is no upload, so the limit is your browser's memory rather than a server's policy.

Does it support JSON with comments?

Comments are not JSON, so they are reported as errors. That is deliberate: a file with comments in it will be rejected by whatever consumes it next.

Does it sort or change my keys?

No. Key order is preserved exactly as you pasted it.

Next

The guide that goes with this