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.
as<T>()
casts the root to the specified type (e.g. JsonArray
or JsonObject
)add()
adds elements to the root arraycapacity()
returns the capacity of the memory poolclear()
empties the document and resets the memory poolcontainsKey()
tests if the root object contains the specified keycreateNestedArray()
creates a nested array attached to the rootcreateNestedObject()
create a nested object attached to the rootgarbageCollect()
reclaims leaked memory blocksoperator[]
gets or sets values in the documentoverflowed()
tells if the memory pool was large enoughis<T>()
tests the type of the rootisNull()
tells if the document is null or emptymemoryUsage()
tells how many bytes are used in the memory poolnesting()
returns the number of nesting layers in the documentremove()
removes an element (or member) at the specified index (or key)set()
replaces the root with the specified valuesize()
returns the number of elements (or members) that the root array (or object) containsto<T>()
clears the document and converts it to the specified type (e.g. JsonArray
or JsonObject
)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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4