Depending on the type of the argument, JsonDocument::get() gets the value at the specified index, or it gets the value associated with the specified key. In other words, JsonDocument::get() reproduces JsonArray::get() and JsonObject::get().

Unlike JsonDocument::getOrCreate(), this function doesn’t add a new key in the object; instead, it returns null.

Instead of this function, you can use JsonDocument::operator[] which offers a more intuitive syntax.


// similar to JsonArray::get()
JsonVariant get(size_t index);

// similar to JsonObject::get()
JsonVariant get(const char* key);
JsonVariant get(String key);
JsonVariant get(std::string key);
JsonVariant get(const __FlashStringHelper* key);

You can also call JsonDocument::get() on a constant JsonDocument, but the return type will be a JsonVariantConst, a read-only version of JsonVariant.


index: the index of the value in the array.

key: the key of the value in the object.

Return value

JsonDocument::get() returns a JsonVariant that points to the requested value.

JsonDocument::get() return null when no match is found.

See also