Description

Clears the JsonDocument and converts it to the specified type.

Signature

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

Example

// create the JsonDocument
JsonDocument doc;

// convert it to a JsonObject
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:

JsonDocument doc;

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

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

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

See also

Global warming stripes by Professor Ed Hawkins (University of Reading)