JsonObject::operator[]
Description
JsonObject::operator[] gets, replaces, or adds a value in the object pointed by the JsonObject.
If the JsonObject is null/unbound, this function does nothing.
If you need to know if the insertion succeed, use JsonVariant::set() instead.
Signatures
MemberProxy operator[](char* key) const;
MemberProxy operator[](const char* key) const; // ⚠️ stores key as a pointer
MemberProxy operator[](const __FlashStringHelper* key) const;
MemberProxy operator[](const String& key) const;
MemberProxy operator[](const std::string& key) const;
MemberProxy operator[](std::string_view key) const;
Arguments
key: the key that the value will be associated with.
All types are stored by copy, except const char* which is stored by pointer.
Return value
JsonObject::operator[] return a proxy class that allows using the JsonObject like a dictionary.
If this concept of proxy class is unfamiliar to you, just think of a JsonVariant instead.
Example
StaticJsonDocument<256> doc;
JsonObject object = doc.to<JsonObject>();
object["hello"] = "world";
const char* world = object["hello"];