Description

StaticJsonDocument is a JsonDocument that allocates its memory pool in-place, so it doesn’t rely on dynamic memory allocation.

Because it doesn’t call malloc() and free(), StaticJsonDocument is slightly faster than DynamicJsonDocument.

If you declare a local variable of type StaticJsonDocument, it allocates the memory pool in the stack memory. Beware not to allocate a memory pool too large in the stack because it would cause a stack overflow. Use StaticJsonDocument for small documents (below 1KB) and switch to a DynamicJsonDocument if it’s too large to fit in the stack memory.

Member functions

Example

Here is a program that deserializes a JSON document using a StaticJsonDocument

StaticJsonDocument<200> doc; // <- a little more than 200 bytes in the stack

char json[] = "{\"hello\":\"world\"}";
deserializeJson(doc, json);

const char* world = doc["hello"];

See also