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.


size_t memoryUsage() const;


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

JsonObject object =<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

See also