Description

JsonDocument::nesting() returns the depth (i.e., the nesting level) of the document.

You can use use the result for DeserializationOption::NestingLimit

JSON Nesting
null 0
"string" 0
[0] 1
[[0]] 2
{"a":0} 1
{"a":{"b":0}} 2
{"a":{"b":[0]}} 3

Signature

size_t nesting() const;

Example

const char* json = "{\"list\":[{\"value\":\"1\"}]}";
JsonDocument doc;
deserializeJson(doc, json);
Serial.println(doc.nesting());  // prints 3
Global warming stripes by Professor Ed Hawkins (University of Reading)