One member or item per line, indented 2 spaces per level.
Strings and numbers are copied exactly as written, so escapes and number formats are unchanged.
About the JSON formatter and validator
The validator parses the text with the RFC 8259 grammar: objects, arrays, double-quoted strings, numbers, true, false and null, and nothing else. If parsing succeeds, it prints the same values back, either with one member per line and 2 spaces, 4 spaces or a tab per level, or minified with every space outside strings removed. If it fails, it reports the line and column where the grammar broke and what it expected there.
Developers use it to read API responses and config files and to shrink payloads. The default object has 6 keys and 10 values nested 2 levels deep, and pretty-printing it with 2 spaces grows it from 127 to 170 bytes.
Strings and numbers are copied exactly as written, so escapes survive and a large integer such as 12345678901234567890123 keeps every digit.
How to format and validate JSON
JSON is valid when it follows the RFC 8259 grammar: objects in braces, arrays in brackets, double-quoted strings and keys, numbers, true, false and null, with commas only between items. Formatting changes whitespace only. Pretty-printing puts each member on its own line, and minifying strips every space outside strings.
Pretty-printing and minifying
This 25-byte document:
{"id":7,"tags":["a","b"]}
Pretty-printed with 2 spaces, it becomes 47 bytes:
{
"id": 7,
"tags": [
"a",
"b"
]
}
With 4 spaces it is 61 bytes. All three versions parse to the same data, so minify for transfer and pretty-print for reading and diffs.
Common JSON syntax errors
Trailing commas: [1, 2,]
Single quotes: {'a': 1}
Unquoted keys: {a: 1}
Comments: // and /* */ belong to JSONC and JSON5, not JSON.
JavaScript-only numbers: NaN, Infinity, 0x10, +1, 007 and .5 are all invalid. Write 0.5, and use null or a string for a missing value.
Raw control characters: a literal tab or line break inside a string must be written \t or \n.
Several documents pasted together: two objects in a row are two JSON texts. Wrap them in an array.
Finding the real error
A parser reports where it noticed the problem, which can be after the actual mistake. Here the missing comma belongs at the end of line 2, but the error points to line 3, column 3, where "b" starts:
{
"a": 1
"b": 2
}
Check the character just before the reported position first, then look further back for an unclosed quote or bracket.
Counts and sizes
Scenario
Keys
Depth
Values
Output bytes
Default
6
2
10
170
Minified default
6
2
10
127
Root number
0
0
1
2
Duplicate keys
5
2
6
64
Large exact integer
1
1
2
42
Default is a 127-byte object, {"name":"CalcOpenly",…,"license":null}, pretty-printed with 2 spaces to 170 bytes. Minified default is the same object minified, and Root number is the document 42, which is valid JSON on its own.
Values count every object, array, string, number, boolean and null. The default's 10 are 1 object, 1 array, 5 strings, 1 number, 1 boolean and 1 null; its 6 keys are counted separately. Depth counts nested containers: 0 for a bare 42, 1 for a flat object.
Large numbers and duplicate keys
RFC 8259 allows any number of digits, but many parsers store numbers as IEEE 754 doubles, which are exact only up to 2^53 − 1 = 9,007,199,254,740,991.
JavaScript's JSON.parse turns 12345678901234567890123 into 1.2345678901234568e+22, so send IDs that large as strings. Number tokens are copied as written here, which is how the Large exact integer row keeps a 30-digit id intact.
Duplicate keys are legal but unreliable: RFC 8259 says names SHOULD be unique, and JSON.parse('{"a":1,"a":2}') keeps only the last value.
The Duplicate keys row, {"a":1,"a":2,"nested":{"a":3,"a":4}}, keeps all four a members and warns, so you can fix the source before another parser picks a different one.
Limits and preserved details
Up to 200,000 characters. Any JSON value can be the top level, including a bare number or string.
Sorting compares keys by Unicode code point and leaves array order alone.
String escapes such as \u00e9 are copied as written, not turned into é.
The text is written into the page address and on-device history, so strip tokens and personal data from API responses first.
If a digest must match, hash the exact bytes with the hash calculator: indentation, key order and a trailing newline all change them.
Checked against: RFC 8259 §2 (any value may be the top-level text)
Empty containers stay on one line
JSON
{"a":[],"b":{}}
Output
Pretty-print
Indent with
4 spaces
Formatted JSON
{
"a": [],
"b": {}
}
Keys
2
Checked against: Independent calculation
Questions
What are the most common JSON syntax errors?
Trailing commas, single quotes and unquoted keys cause most failures, because JSON requires double quotes around every string and key and allows no comma after the last item. Comments, NaN, Infinity and hex numbers are also invalid under RFC 8259, although JavaScript accepts some of them in code. The error message here gives the line and column, so you can go straight to the character that broke the parse.
Does JSON allow comments?
No. RFC 8259 and ECMA-404 define no comment syntax, so a standard parser rejects // and /* */. Douglas Crockford removed comments from the format early on because people were using them to hold parser directives. Config files that need comments use JSON5 or JSONC, the format of VS Code's settings.json, and this validator reports those files as invalid JSON.
How large can a JSON number be?
RFC 8259 sets no limit, but it warns that only integers between −(2^53 − 1) and 2^53 − 1 = 9,007,199,254,740,991 are sure to interoperate, since many parsers use IEEE 754 doubles. This tool copies numbers digit for digit, but JavaScript's JSON.parse turns 12345678901234567890123 into 1.2345678901234568e22, so send large IDs as strings.
Are duplicate keys allowed in JSON?
RFC 8259 says the names within an object SHOULD be unique, so duplicates are legal but unreliable: JavaScript's JSON.parse and Python's json module keep only the last value, while other parsers keep the first or reject the document. This validator accepts them but warns with the line and column of the object, so you can remove the duplicate before another system reads it differently.
What is the difference between pretty-printing and minifying JSON?
Pretty-printing puts each member on its own line with 2 or 4 spaces or a tab per level, which makes the data easy to read and diff; minifying removes every space and line break outside strings for transfer. Both describe exactly the same data. The default example grows from 127 to 170 bytes when pretty-printed, and the minify example shrinks from 45 to 33 bytes.
This calculator includes 6 worked examples with independently sourced answers. They run in the test suite, and you can run them here too.
Put this calculator on your site
Paste this where you want the calculator to appear. It is free to use, it stays in step with corrections made here, and the credit line below it links back so your readers can find the full version.