diff --git a/include/ArduinoJson/JsonObject.hpp b/include/ArduinoJson/JsonObject.hpp index fef00140..bfea4bc6 100644 --- a/include/ArduinoJson/JsonObject.hpp +++ b/include/ArduinoJson/JsonObject.hpp @@ -99,10 +99,6 @@ class JsonObject : public Internals::JsonPrintable, // Returns the list node that matches the specified key. node_type *getNodeAt(key_type key) const; - // Returns the list node that matches the specified key, creating it if - // needed. - node_type *getOrCreateNodeAt(key_type key); - // The instance returned by JsonObject::invalid() static JsonObject _invalid; }; diff --git a/src/JsonObject.cpp b/src/JsonObject.cpp index bce43f04..02c6b760 100644 --- a/src/JsonObject.cpp +++ b/src/JsonObject.cpp @@ -29,8 +29,16 @@ const JsonVariant &JsonObject::at(const char *key) const { } JsonVariant &JsonObject::operator[](const char *key) { - node_type *node = getOrCreateNodeAt(key); - return node ? node->content.value : JsonVariant::invalid(); + node_type *existingNode = getNodeAt(key); + if (existingNode) return existingNode->content.value; + + node_type *newNode = createNode(); + if (!newNode) return JsonVariant::invalid(); + + newNode->content.key = key; + addNode(newNode); + + return newNode->content.value; } void JsonObject::remove(char const *key) { removeNode(getNodeAt(key)); } @@ -56,18 +64,6 @@ JsonObject::node_type *JsonObject::getNodeAt(const char *key) const { return NULL; } -JsonObject::node_type *JsonObject::getOrCreateNodeAt(const char *key) { - node_type *existingNode = getNodeAt(key); - if (existingNode) return existingNode; - - node_type *newNode = createNode(); - if (!newNode) return NULL; - - newNode->content.key = key; - addNode(newNode); - return newNode; -} - void JsonObject::writeTo(JsonWriter &writer) const { node_type *node = _firstNode;