How to create complex nested objects?
To create a nested object, call createNestedObject()
.
To create a nested array, call createNestedArray()
.
For example:
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
JsonObject& weather = root.createNestedObject("weather");
weather["temperature"] = 12;
weather["condition"] = "cloudy";
JsonArray& coords = root.createNestedArray("coords");
coords.add(48.7507371, 7);
coords.add(2.2625587, 7);
root.prettyPrintTo(Serial);
will generate:
{
"weather": {
"temperature": 12,
"condition": "cloudy"
},
"coords": [
48.7507371,
2.2625587
]
}
The ArduinoJson Assistant can generate the skeleton for you.
See: