Skip to content
Technologydeveloper

JSON Formatter and Validator

JSON formatting, minification and validation. Formatting requires parsing, so a document that formats is valid, and one that does not tells you where it broke.

Also called: json validator, json pretty print.

Mode
Result
{ "region": "IN", "rates": [ 5, 20, 30 ], "verified": false }

{ "region": "IN", "rates": [ 5, 20, 30 ], "verified": false } Valid JSON with 3 keys at a maximum depth of 3. 50 characters in, 81 out. Pretty printing adds whitespace for readability and changes nothing semantically.

Keys
3
Maximum nesting depth
3
Input length
50
Output length
81
Arrays
1
On size
Pretty printing adds whitespace for readability and changes nothing semantically.
On privacy
This runs in your browser. Nothing you paste is sent anywhere, which matters for anything sensitive.
Method and background

How this is calculated

The input is parsed and re-serialised, which means formatting and validation are the same operation: invalid JSON cannot be formatted. Minifying strips whitespace for transmission. Sorting keys produces a canonical ordering, which makes two documents with the same content compare equal in a diff regardless of the order they were written in. Note that JSON objects have no defined key order, so sorting changes nothing semantically.

formatting is a parse and a re-serialise, which is why it also validates
J
The document

Worked examples

Each of these is asserted on every build. If a change to the engine ever moved one of these answers, the build would fail before the page could print it.

formatting a small object

JSON
{"region":"IN","rates":[5,20,30],"verified":false}
Mode
Pretty print
Indent spaces
2

Result{ "region": "IN", "rates": [ 5, 20, 30 ], "verified": false }

Three keys, one array; the array elements sit at depth three

Open this example

minifying is idempotent on compact input

JSON
{"a":1}
Mode
Minify
Indent spaces
2

Result{"a":1}

boundary

Open this example

Method and limits

What it assumes

  • Standard JSON. Comments and trailing commas are not permitted and will fail.

What it deliberately does not model

  • JSON with comments, trailing commas or single quotes is not valid JSON and will not parse.
  • Very large numbers lose precision, since JSON numbers become doubles.
  • Key order is not semantically meaningful, so sorting is a presentation choice.

Formula version 1.0.0 · definition 1.0.0 · India · Report a problem with this calculator

Frequently asked questions

Why does my JSON not parse?
Most often a trailing comma, a comment, or single quotes instead of double. All three are valid JavaScript and none are valid JSON.
Does sorting keys change the meaning?
No. JSON objects have no defined key order, so sorting is purely a presentation choice that makes diffs comparable.