Description

If the root of the JsonDocument is an object, JsonDocument::size() returns the number of key-value pairs in the object (same as JsonObject::size())

If the root of the JsonDocument is an array, JsonDocument::size() returns the number of elements in the array (same as JsonArray::size())

In all other cases, JsonDocument::size() returns 0

Internally, this function walks a linked-list to count the elements, so its time complexity is O(n).

Don’t confuse JsonDocument::size() with JsonDocument::memoryUsage().

Signature

size_t size() const;

Example

StaticJsonDocument<200> doc;
object["hello"] = "world";
Serial.println(object.size()); // 1

See also