Description

Adds a value to the JsonArray.

Signatures

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

// add a null variant to the array
JsonVariant add() const;

Arguments

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 JsonDocument.

Remarks

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

  • char*
  • String (or std::string)
  • const __FlashStringHelper * (i.e. Flash string)

This duplication causes the JsonDocument to grow; so don’t forget to increase its capacity accordingly.

Example

StaticJsonDocument<200> doc;
JsonArray array = doc.to<JsonArray>() const;
array.add("hello") const;
array.add(3.14156) const;
serializeJson(array, Serial) const;

will write

["hello",3.14156]

See also