JsonDocument::getOrAddMember()
Removed in ArduinoJson 6.20: use JsonDocument::operator[]
instead.
Description
JsonDocument::getOrAddMember()
reproduces JsonObject::getOrAddMember()
. It requires that the JsonDocument
contains an object, and it can convert the document if needed.
-
If the
JsonDocument
contains an object,JsonDocument::getOrAddMember()
gets the value associated with the specified key. If the key is not present in the object, this function adds a new key-value pair to the object. -
If the
JsonDocument
contains something else, thisJsonDocument::getOrAddMember()
does nothing. -
If the
JsonDocument
is empty,JsonDocument::getOrAddMember()
converts theJsonDocument
to an object and performs its usual task.
Instead of this function, you can use JsonDocument::operator[]
which offers a more intuitive syntax.
Signatures
JsonVariant getOrAddMember(const char* key);
JsonVariant getOrAddMember(String key);
JsonVariant getOrAddMember(std::string key);
JsonVariant getOrAddMember(const __FlashStringHelper* key);
JsonVariant getOrAddMember(std::string_view key);
Arguments
key
: the key of the value in the object.
As usual, ArduinoJson makes a copy of the key in the JsonDocument
, except if it’s a const char*
.
Return value
If the key is already present in the object, this function returns a JsonVariant
that points to the associated value.
If the key is not present in the object, this function adds a new key-value pair to the object and returns a JsonVariant
that points to the value. The returned JsonVariant
could be null if there were not enough room in the JsonDocument
.