The member functions begin() and end() return STL-style iterators. You can use these iterators to enumerate all the elements in the array pointed by the JsonArrayConst.

These functions reproduce the containers in the C++ Standard Library and allow you to use the “ranged-based for loop” feature of C++11. See the example below.


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

Return value

begin() returns an iterator to the first element of the array.

end() returns an iterator to the element after the last. This iterator must not be dereferenced because it is out of the array. It’s a placeholder to detect the end of the array.

JsonArrayConst::iterator points to a JsonVariantConst. You can dereference the iterator with the usual * and -> operators.


char json[] = "[\"one\",\"two\",\"three\"]";
DynamicJsonDocument doc(1024);
deserializeJson(doc, json);
JsonArrayConst arr =<JsonArray>();

// using C++11 syntax (preferred):
for (JsonVariantConst value : arr) {
    Serial.println(<const char*>());

// using C++98 syntax (for older compilers):
for (JsonArrayConst::iterator it=arr.begin(); it!=arr.end(); ++it) {
    Serial.println(it->as<const char*>());

The code above would print:


See also