⚠️ Subject to changeVersion 6 is currently in beta, so the API
Unless you need the new features of version 6 (e.g. MessagePack), please use version 5.13.4.
Version 6 should stay in beta stage until march 2019.
JsonObject::getOrCreate() gets the value associated with the specified key, or creates it if it doesn’t exist.
JsonObject is null, this function does nothing.
Instead of this function, you can use
JsonObject::operator which offers a more intuitive syntax.
JsonVariant getOrCreate(char* key) const; JsonVariant getOrCreate(const char* key) const; JsonVariant getOrCreate(const __FlashStringHelper* key) const; JsonVariant getOrCreate(const String& key) const; JsonVariant getOrCreate(const std::string& key) const;
key: the key of the value in the object.
As usual, ArduinoJson makes a copy of the key in the
JsonDocument, except if it’s a
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.
If the key is already present in the object, this function returns
JsonVariant that points to the associated value.
If the key is not present in the object, this function adds a new value in the object and returns a
JsonVariant that points to this value.