JsonObject::remove() removes a key-value pair from the object pointed by the JsonObject.

If the JsonObject is null, this function does nothing.


void remove(const char* key) const;
void remove(const __FlashStringHelper* key) const;

void remove(const String& key) const;
void remove(const std::string& 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 ⚠️

Because JsonDocument contains a monotonic allocator, this function cannot release the memory associated with the removed key-value pair.

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