Description

JsonObjectConst::memoryUsage() returns the number of bytes used by the object pointed by the JsonArray.

Unlike JsonDocument::memoryUsage(), the result doesn’t include leaked memory.

Signature

size_t memoryUsage() const;

Example

char json[] = "{\"a\":1,\"b\":2}";
StaticJsonDocument<200> doc;
deserializeJson(doc, json);
doc.remove("b"); // remove last member to show the effect of a leak

JsonObjectConst object = doc.as<JsonObject>();

Serial.println(object.memoryUsage());  // 10 on AVR
Serial.println(doc.memoryUsage());     // 16 on AVR

See also

Global warming stripes by Professor Ed Hawkins (University of Reading)