JsonObject::operator[] gets, replaces, or adds a value in the object pointed by the JsonObject.

If the JsonObject is null, this function does nothing.

If you need to know if the insertion succeed, use JsonVariant::set() instead.


MemberProxy operator[](char* key) const;
MemberProxy operator[](const char* key) const;
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;


key: the key that the value will be associated with.

As usual, ArduinoJson makes a copy of the key in the JsonDocument, except if it’s a const char*.

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.

String duplication

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


JsonDocument doc;
JsonObject object =<JsonObject>();
object["hello"] = "world";
const char* world = object["hello"];

See also