JsonVariant::operator[]
Description
JsonVariant::operator[]
gets, replaces, adds a value in the JsonVariant
.
Depending on the argument type the JsonVariant
can be used like a JsonArray
or a JsonObject
.
Signatures
// mimics a JsonArray
ElementProxy operator[](size_t index) const;
// mimics a JsonObject
MemberProxy operator[](const char* key) const;
MemberProxy operator[](char* key) const;
MemberProxy operator[](const String& key) const;
MemberProxy operator[](const std::string& key) const;
MemberProxy operator[](string_view key) const; // 🆕 (added in 6.18.1)
MemberProxy operator[](const __FlashStringHelper* key) const;
Arguments
index
: the index in the JsonArray
.
key
: the key in the JsonObject
Return value
A proxy class that allows using the JsonVariant
as an array or a dictionary. If this concept of proxy class is unfamiliar to you, just think of a JsonVariant
instead.
Please see JsonArray::operator[]
and JsonObject::operator[]
for explanations about ElementProxy
and MemberProxy
.
String duplication
ArduinoJson makes a copy of the string when you call this function with one of the following types:
char*
String
(orstd::string
)const __FlashStringHelper*
(i.e. Flash string)
This duplication consumes some space in the JsonDocument
; don’t forget to increase its capacity accordingly.