Skip to main content
Calnex LogoCalnex
Developer Tools

JSON Formatter & Validator

Parse pasted JSON, report validity, key count, nesting depth and root type, then pretty-print, minify or re-serialize it.

JSON Input

Drag & drop JSON file here, or click to upload

Output Result

ValidationVALID ✓
Total Keys6
Nesting Depth2
Root TypeObject

Example input and result

{"name":"Ada","active":true}
{
  "name": "Ada",
  "active": true
}

Use Format to inspect nested API data, Minify to remove layout whitespace, and Validate to locate syntax errors. Every mode parses the text into JavaScript values before serializing it again. Keep the original payload when exact number spelling, duplicate names or byte-for-byte equality matters.

What counts as a key and as nesting depth?

Total Keys counts object property names at every level, not array elements. An array of primitives reports 0 keys, while keys inside objects within an array are counted. Nesting Depth is the maximum level reached: the root value is level 0 and each nested object or array adds one. An empty object or empty array returns current + 1, so an empty root object reports depth 1.

Does Validate Only skip the output block?

No. Validate Only still produces an output labeled Normalized JSON, which is the parsed value re-serialized with two-space indentation. Format and Minify are explicit transformations; Validate Only confirms syntax and shows a canonical form. All three modes require successful parsing; on failure only the INVALID badge and Error Message are returned.

Do not use reformatting as a lossless archive

JSON.parse uses JavaScript numbers. An integer above 9007199254740991 can lose precision; 1.00 may serialize as 1. Duplicate property names collapse to the final value. Quote identifiers that must remain exact, and compare the original text before replacing a signed or hashed payload.

Four JSON checks before copying an API response (4)

How do I format a small nested object and see its key count and depth?

JSON Text
{"a":1,"b":{"c":2}}
Action
Format (Pretty Print)
  1. Enter {"a":1,"b":{"c":2}} with Action set to Format (Pretty Print).
  2. Parsing succeeds, so Validation is VALID ✓. Keys a, b and c give Total Keys 3; depth reaches the nested value, giving 2; Root Type is Object.
  3. The output is the same object with two-space indentation across multiple lines.
Validation
VALID ✓
Total Keys
3
Nesting Depth
2
Root Type
Object
Formatted JSON
{ "a": 1, "b": { "c": 2 } }

Key count includes nested keys, and depth counts levels below the root. Formatting does not change values or the parsed key order. This sample keeps its values; that does not guarantee lossless serialization for arbitrary JSON.

What does minifying an array of numbers report?

JSON Text
[1,2,3]
Action
Minify (Single Line)
  1. Enter [1,2,3] with Action set to Minify (Single Line).
  2. Parsing succeeds. There are no object keys, so Total Keys is 0; the array is one level deep, so Nesting Depth is 1; Root Type is Array.
  3. The output is [1,2,3] on a single line.
Validation
VALID ✓
Total Keys
0
Nesting Depth
1
Root Type
Array
Formatted JSON
[1,2,3]

Arrays of primitives have zero keys, which can surprise users expecting element counts. Minify removes whitespace but does not reorder or alter values. This sample keeps its values; that does not guarantee lossless serialization for arbitrary JSON.

Why did a duplicate role disappear?

JSON Text
{"role":"reader","role":"editor"}
Action
Minify (Single Line)
  1. Paste {"role":"reader","role":"editor"} and select Minify.
  2. The parsed object has one role property with the final value editor.
Total Keys
1
Formatted JSON
{"role":"editor"}

This is a parser consequence, not a duplicate-key warning. Keep the source if repeated names need investigation.

A trailing comma stops validation

JSON Text
{"items":[1,2,]}
Action
Validate Only
  1. Paste {"items":[1,2,]} and select Validate.
  2. Remove the comma after 2, then run again.
Validation
INVALID ✗

The invalid state has no formatted result. Error wording depends on the browser, so the example checks the validation badge.

Frequently asked questions

Why does my array show 0 total keys?

Total Keys counts object property names only. Array elements are not keys, so an array of numbers, strings or booleans reports 0. Keys inside objects within the array are counted.

What happens if my JSON is invalid?

The tool returns an INVALID ✗ validation badge and an Error Message from the parser. Key count, depth, root type and output are not produced until the text parses successfully.

Is the formatted output exactly my original text?

No. The tool parses then re-serializes, so whitespace and indentation are regenerated with two spaces. Duplicate keys are resolved by the parser, and number formatting follows JavaScript serialization.

Complementary Calculators