Description

Clears the JsonDocument and converts it to the specified type.

Signature

JsonArray   to<JsonArray>();
JsonObject  to<JsonObject>();
JsonVariant& to<JsonVariant>();

Example

// allocate the JsonDocument
StaticJsonDocument<200> doc;

// convert it to a JsonObjec
JsonObject root = doc.to<JsonObject>();

// set values
root["hello"] = "world";

Invalidates references

Because this function releases memory owned by the JsonDocument, it invalidates all references acquired before.

Example:

DynamicJsonBuffer doc;

JsonObject root1 = doc.to<JsonObject>();

JsonObject root2 = doc.to<JsonObject>();

// Don't use root1 here, because it's dangling!