By Mian Ali Khalid · Published · How we build and test tools
How to use the json statistics
- Paste or type your JSON data into the text area above.
- The tool parses the input immediately using
JSON.parseand walks the resulting tree. - Review the generated json statistics, including total keys, maximum depth and value type counts.
- If the input contains strings, check the minimum, maximum and average string lengths measured in Unicode code points.
What these json statistics measure
The analyzer walks every node in the parsed JSON tree recursively. It counts each property name as one key, whether it belongs to a top-level object or an object nested inside an array. The maximum depth starts at zero for primitive roots (like a bare number or string) and increases by one for every object or array boundary crossed.
For example, given {"user": {"name": "Ada"}}, the root object sits at depth 1, the inner object at depth 2, and the two keys are user and name. The reported max depth would be 2 and the total keys would be 2. Type counters increment once per value encountered, so an array of three numbers adds 3 to the number count and 1 to the array count.
String length and Unicode handling
JavaScript's native String.prototype.length counts UTF-16 code units, which means characters outside the Basic Multilingual Plane (such as many emoji) register as two units instead of one. This tool uses the spread operator ([...str].length) to count actual Unicode code points, giving accurate string length statistics regardless of the script or symbol used.
If your JSON contains {"flag": "🇺🇸"}, the string length is counted as 2 code points (the two regional indicator symbols), not 4 UTF-16 code units. Minimum, maximum and average lengths are only displayed when the document contains at least one string value.
Common reference values
The table below shows expected json statistics for several typical payloads. Use it to verify your own results or understand how different structures affect the counts.
| JSON input | Keys | Depth | Strings | Numbers | Objects | Arrays |
|---|---|---|---|---|---|---|
null | 0 | 0 | 0 | 0 | 0 | 0 |
[1, 2, 3] | 0 | 1 | 0 | 3 | 0 | 1 |
{"a": 1} | 1 | 1 | 0 | 1 | 1 | 0 |
{"a": {"b": 2}} | 2 | 2 | 0 | 1 | 2 | 0 |
[{"x": "y"}] | 1 | 2 | 1 | 0 | 1 | 1 |
Practical use cases
Understanding the shape of a JSON payload helps when mapping data between formats. If you need to convert JSON to another representation, knowing the exact key count and depth prevents surprises. For instance, before running a json to xml conversion, checking the depth ensures the resulting XML will not exceed your parser's nesting limits.
When preparing tabular output via json to html table or json to markdown table, the total keys and array counts tell you how many columns and rows to expect. Developers generating typed models with tools like json to go struct or json to python class can use the object count to estimate how many distinct types or classes they will need to define.
Edge cases and error handling
The parser uses the native JSON.parse method, which strictly follows RFC 8259. Trailing commas, single quotes, unquoted keys and comments all trigger a parse error with a descriptive message indicating the position where parsing failed. Empty input returns an error asking for valid JSON.
Valid JSON does not have to be an object or array. A bare string like "hello", a number like 42, or the literals true, false and null are all accepted. In these cases the total keys remain zero, the max depth is zero, and only the relevant type counter increments. Extremely deep nesting (thousands of levels) may hit the JavaScript engine's call stack limit; for typical API responses this is never an issue.
Worked examples
| Example | Input | Result |
|---|---|---|
| Simple object | JSON input: {"name": "Ada Lovelace", "age": 36, "active": true} | Total keys: 3; Max depth: 1; Strings: 1; Numbers: 1; Booleans: 1; Objects: 1; Min string length: 12; Max string length: 12; Avg string length: 12 |
| Nested array of objects | JSON input: [{"id": 1, "tags": ["a", "b"]}, {"id": 2, "tags": []}] | Total keys: 4; Max depth: 3; Strings: 2; Numbers: 2; Arrays: 3; Objects: 2; Min string length: 1; Max string length: 1; Avg string length: 1 |
| Deeply nested | JSON input: {"a": {"b": {"c": {"d": "deep"}}}} | Total keys: 4; Max depth: 4; Strings: 1; Objects: 4; Min string length: 4; Max string length: 4; Avg string length: 4 |
| Unicode strings | JSON input: {"emoji": "🚀🌍", "greek": "αβγδ"} | Total keys: 2; Max depth: 1; Strings: 2; Objects: 1; Min string length: 2; Max string length: 4; Avg string length: 3 |
FAQ
What counts as a key in these json statistics?
Every property name in every object throughout the document counts as one key. If the same property name appears in multiple objects, each occurrence is counted separately.
How is maximum depth calculated?
A standalone primitive value has depth 0. Each object or array adds one level. An object containing another object has a depth of 2.
Does the tool handle unicode and emoji correctly?
Yes. String lengths are measured in Unicode code points rather than UTF-16 code units, so emoji and non-Latin scripts produce accurate length statistics.
Can I analyze a JSON array instead of an object?
Absolutely. Arrays are fully supported. The tool counts array elements toward their respective type totals and tracks nesting depth through array boundaries.
Why do I get a parse error on my JSON?
Standard JSON does not allow trailing commas, single quotes, comments or unquoted keys. Ensure your input strictly follows the JSON specification.
Is my data sent to a server?
No. Parsing and analysis happen entirely in your browser. Nothing leaves your device.