ArduinoJson: API Reference



Adds a value to the end of the array.

bool add(bool value);
bool add(float value);
bool add(double value);
bool add(signed char value);
bool add(signed long value);
bool add(signed int value);
bool add(signed short value);
bool add(unsigned char value);
bool add(unsigned long value);
bool add(unsigned int value);
bool add(unsigned short value);
bool add(const char *value);
bool add(const String &value); // see Remarks
bool add(const std::string &value); // see Remarks
bool add(JsonArray &array);
bool add(JsonObject &object);
bool add(const JsonVariant &variant);

value: the value to add to the array.

Return value

true if the value was successfully added.

false if there was not enough memory in the JsonBuffer.


When you call add(const String&) or add(const std::string&), a copy of the string is made, causing the JsonBuffer to grow. The memory allocated for the copy will only be freed when the whole JsonBuffer is discarded. To avoid this behavior, use add(const char*) instead.

StaticJsonBuffer<200> jsonBuffer;
JsonArray& array = jsonBuffer.createArray();
array.add(3.14156, 4);

will write

Fork me on GitHub