JsonObject::createNestedArray() adds a new array to the object pointed by the JsonObject.

If the JsonObject is null, this function does nothing.


JsonArray createNestedArray(char* key) const;
JsonArray createNestedArray(const char* key) const;
JsonArray createNestedArray(const __FlashStringHelper* key) const;

JsonArray createNestedArray(const String& key) const;
JsonArray createNestedArray(const std::string& key) const;
JsonArray createNestedArray(std::string_view key) const;  // 🆕 (added in 6.18.1)


key: the key to associate with the array.

As usual, ArduinoJson makes a copy of a string in the JsonDocument, except if it’s a const char*.

String duplication

ArduinoJson makes a copy of the string when you call this function with one of the following types:

This duplication consumes some space in the JsonDocument; don’t forget to increase its capacity accordingly.

Return value

JsonObject::createNestedArray() returns a JsonArray that points to the newly created array.

JsonObject::createNestedArray() return null if the memory allocation fails; in which case JsonArray::isNull(), returns true.


StaticJsonDocument<256> doc;
JsonObject root =<JsonObject>();
root["status"] = "on";
JsonArray levels = root.createNestedArray("levels");
serializeJsonPretty(root, Serial);

will print

  "status": "on",
  "levels": [

See also