Description

JsonDocument::memoryUsage() the number of bytes used in the JsonDocument.

Unlike JsonArray::memoryUsage(), JsonObject::memoryUsage(), and JsonVariant::memoryUsage(), the result includes leaked memory.

Use this function at design time to measure the required capacity for the JsonDocument.

Signature

size_t memoryUsage() const;

Example

char json[] = "{\"a\":1,\"b\":2}";
StaticJsonDocument<200> doc;
deserializeJson(doc, json);

JsonObject object = doc.as<JsonObject>();
object.remove("b"); // remove last member to show the effect of a leak

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