Description

A collection of named JsonVariant.

The constructor is private; you cannot instantiate a JsonObject directly, you have to use a JsonDocument.

Because the memory of a JsonObject is located a JsonDocument, you always manipulate it through reference, and you cannot copy it.

Computing the size

The macro JSON_OBJECT_SIZE(n) returns the size of a JsonObject that contains n elements. This value only includes the size of the JsonObject; if you have nested objects or strings, you need to add their sizes as well.

You can use the ArduinoJson Assistant to generate the complete expression.

Example

StaticJsonDocument<200> doc;

// create an object
JsonObject object1 = doc.to<JsonObject>();
object1["hello"] = "world";

// parse a JSON object
char json[] = "{\"hello\":\"world\"}";
deserializeJson(doc, json);
JsonObject object2 = doc.as<JsonObject>();

Member functions

See also