Removes the element at the specified key.


void remove(const char* key) const;
void remove(const String& key) const;
void remove(const std::string& key) const;
void remove(const __FlashStringHelper* key) const;


key: the key to remove from the object.


JsonObject object =<JsonObject>();
object["A"] = 1;
object["B"] = 2;
object["C"] = 3;
serializeJson(object, Serial);

will print the following string to the serial output:


See also

Causes memory leaks

This function doesn’t free the memory allocated to the element in the JsonDocument.

This is a conscious design decision made to keep the JsonDocument fast and small, which is a fundamental principle of the library.

As a consequence, you cannot remove and add elements in a loop, otherwise the JsonDocument will overflow.

Don’t try to keep the state of your application in a JsonObject, instead use custom structures.