Removed in ArduinoJson 6.20: use JsonObject::operator[] instead.


JsonObject::getOrAddMember() gets the value associated with the specified key, or creates it if it doesn’t exist.

If the JsonObject is null/unbound, this function does nothing.

Instead of this function, you can use JsonObject::operator[] which offers a more intuitive syntax.


JsonVariant getOrAddMember(char* key) const;
JsonVariant getOrAddMember(const char* key) const;  // ⚠️ stores key as a pointer
JsonVariant getOrAddMember(const __FlashStringHelper* key) const;

JsonVariant getOrAddMember(const String& key) const;
JsonVariant getOrAddMember(const std::string& key) const;
JsonVariant getOrAddMember(std::string_view key) const;


key: the key of the value in the object.

All types are stored by copy, except const char* which is stored by pointer.

Return value

If the key is already present in the object, this function returns JsonVariant that points to the associated value.

If the key is not present in the object, this function adds a new value in the object and returns a JsonVariant that points to this value.

See also