Description

JsonVariant::operator[] gets, replaces, or 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; // see Remarks
MemberProxy operator[](const String& key) const; // see Remarks
MemberProxy operator[](const std::string& key) const; // see Remarks
MemberProxy operator[](const __FlashStringHelper* key) const; // see Remarks

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.

Remarks

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

This duplication consumes some space in the JsonDocument; don’t forget to increase its capacity accordingly.

See also