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.

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

Signatures

// mimics a JsonArray
ElementProxy operator[](size_t index) const;

// mimics a JsonObject
MemberProxy operator[](const char* key) const;  // ⚠️ stores key as a pointer
MemberProxy operator[](char* key) const;
MemberProxy operator[](const String& key) const;
MemberProxy operator[](const std::string& key) const;
MemberProxy operator[](string_view key) const;
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.

See also