Description

Returns an iterator that can be used to get all key-value pairs in the object.

Signatures

JsonObject::iterator begin() const;
JsonObject::iterator end() const;

Return value

A forward iterator pointing to a JsonPair, which itself contains two members key and value.

Example

char json[] = "{\"first\":\"hello\",\"second\":\"world\"}";
DynamicJsonDocument doc;
deserializeJson(doc, json);
JsonObject root = doc.as<JsonObject>();

// using C++11 syntax (preferred):
for (auto kv : root) {
    Serial.println(kv.key().c_str());
    Serial.println(kv.value().as<char*>());
}

// using C++98 syntax (for older compilers):
for (JsonObject::iterator it=root.begin(); it!=root.end(); ++it) {
    Serial.println(it->key().c_str());
    Serial.println(it->value().as<char*>());
}

The code above would print:

first
hello
second
world

See also