JsonDocument::createNestedArray() | ArduinoJson 6
Maybe your like
Description
Depending on the argument, JsonDocument::createNestedArray() behaves like JsonArray::createNestedArray() or JsonObject::createNestedArray().
Without argument, JsonDocument::createNestedArray() creates an array and appends it to the root array. If the document’s root is not an array, this function does nothing. If the document is empty, this function initializes the document’s root as an array.
With a string argument, JsonDocument::createNestedArray() creates an array and assigns it to the specified key. If the document’s root is not an object, this function does nothing. If the document is empty, this function initializes the document’s root as an object.
As you see, when the JsonDocument is empty, this function automatically converts it to the appropriate type (array or object). This feature allows creating nested arrays like that:
DynamicJsonDocument doc(1024); JsonArray ports = doc.createNestedArray("ports"); ports.add("80"); ports.add("443");The lines above create the following document:
{"ports":[80,443]}Signature
// similar to JsonArray::createNestedArray() JsonArray createNestedArray(); // similar to JsonObject::createNestedArray() JsonArray createNestedArray(char* key); JsonArray createNestedArray(const char* key); JsonArray createNestedArray(const __FlashStringHelper* key); JsonArray createNestedArray(const String& key); JsonArray createNestedArray(const std::string& key); JsonArray createNestedArray(std::string_view key);Return value
JsonDocument::createNestedArray() returns a JsonArray that points to the new array.
JsonDocument::createNestedArray() returns null when the memory allocation fails; in which case JsonArray::isNull() return true.
Examples
Like an array
StaticJsonDocument<200> doc; JsonArray arr = doc.createNestedArray(); arr.add("hello world"); serializeJson(doc, Serial);will write the following line to the serial port:
[["hello world"]]Like an object
StaticJsonDocument<200> doc; JsonArray array = doc.createNestedArray("hello"); array.add("world"); serializeJson(doc, Serial);will write the following line to the serial port:
{"hello":["world"]}See also
- JsonArray::createNestedArray()
- JsonObject::createNestedArray()
- Home
- Version 6
- API
- JsonDocument
- createNestedArray()
Tag » Arduino Json 6 Nested Array
-
JsonArray | ArduinoJson 6
-
ArduinoJson Nested Array - Programming Questions - Arduino Forum
-
How To Create Nested Json Using ArduinoJson On ESP8266
-
Nested Array Can Not Contain Other Arrays? · Issue #51 - GitHub
-
How To Create Nested Object In Nested Array? · Issue #380 - GitHub
-
ESP8266: Parsing JSON Arrays - Techtutorialsx
-
C++ ArduinoJson::JsonArray::createNestedObject() - CPPSECRETS
-
[தமிழ்] Create JSON String With Nested JSON & JSON Array
-
Mastering ArduinoJson 6 - PDFCOFFEE.COM
-
Arduino -Sending And Receiving JSON Data Over MQTT
-
Fun With ESP32 + Arduino (15) ArduinoJSON Library (V6 Version)
-
Decoding And Encoding JSON Arduino | Random Nerd Tutorials
-
ArduinoJSON: Serialize And Deserialize - Tutorialspoint
-
How To Use A Multidimensional Json Array In Android Studio ...