diff --git a/CHANGELOG.md b/CHANGELOG.md index be4e0e4f..0259f145 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,3 +28,4 @@ HEAD * Call `shrinkToFit()` in `deserializeJson()` and `deserializeMsgPack()` * `serializeJson()` and `serializeMsgPack()` replace the content of `std::string` and `String` instead of appending to it * Replace `add()` with `add()` (`add(T)` is still supported) +* Remove `createNestedArray()` and `createNestedObject()` (use `to()` and `to()` instead) diff --git a/examples/JsonGeneratorExample/JsonGeneratorExample.ino b/examples/JsonGeneratorExample/JsonGeneratorExample.ino index f5e1ce86..05a26c22 100644 --- a/examples/JsonGeneratorExample/JsonGeneratorExample.ino +++ b/examples/JsonGeneratorExample/JsonGeneratorExample.ino @@ -22,7 +22,7 @@ void setup() { doc["time"] = 1351824120; // Add an array. - JsonArray data = doc.createNestedArray("data"); + JsonArray data = doc["data"].to(); data.add(48.756080); data.add(2.302038); diff --git a/examples/JsonServer/JsonServer.ino b/examples/JsonServer/JsonServer.ino index cfebc8a0..0d81a3d9 100644 --- a/examples/JsonServer/JsonServer.ino +++ b/examples/JsonServer/JsonServer.ino @@ -60,7 +60,7 @@ void loop() { JsonDocument doc; // Create the "analog" array - JsonArray analogValues = doc.createNestedArray("analog"); + JsonArray analogValues = doc["analog"].to(); for (int pin = 0; pin < 6; pin++) { // Read the analog input int value = analogRead(pin); @@ -70,7 +70,7 @@ void loop() { } // Create the "digital" array - JsonArray digitalValues = doc.createNestedArray("digital"); + JsonArray digitalValues = doc["digital"].to(); for (int pin = 0; pin < 14; pin++) { // Read the digital input int value = digitalRead(pin); diff --git a/examples/JsonUdpBeacon/JsonUdpBeacon.ino b/examples/JsonUdpBeacon/JsonUdpBeacon.ino index 39a126af..c5d5b432 100644 --- a/examples/JsonUdpBeacon/JsonUdpBeacon.ino +++ b/examples/JsonUdpBeacon/JsonUdpBeacon.ino @@ -50,7 +50,7 @@ void loop() { JsonDocument doc; // Create the "analog" array - JsonArray analogValues = doc.createNestedArray("analog"); + JsonArray analogValues = doc["analog"].to(); for (int pin = 0; pin < 6; pin++) { // Read the analog input int value = analogRead(pin); @@ -60,7 +60,7 @@ void loop() { } // Create the "digital" array - JsonArray digitalValues = doc.createNestedArray("digital"); + JsonArray digitalValues = doc["digital"].to(); for (int pin = 0; pin < 14; pin++) { // Read the digital input int value = digitalRead(pin); diff --git a/extras/scripts/wandbox/JsonGeneratorExample.cpp b/extras/scripts/wandbox/JsonGeneratorExample.cpp index 18d68b61..4e710986 100644 --- a/extras/scripts/wandbox/JsonGeneratorExample.cpp +++ b/extras/scripts/wandbox/JsonGeneratorExample.cpp @@ -22,7 +22,7 @@ int main() { // Add an array. // - JsonArray data = doc.createNestedArray("data"); + JsonArray data = doc["data"].to(); data.add(48.756080); data.add(2.302038); diff --git a/extras/tests/JsonArray/CMakeLists.txt b/extras/tests/JsonArray/CMakeLists.txt index e3cc655f..1cf09bd3 100644 --- a/extras/tests/JsonArray/CMakeLists.txt +++ b/extras/tests/JsonArray/CMakeLists.txt @@ -7,7 +7,6 @@ add_executable(JsonArrayTests clear.cpp compare.cpp copyArray.cpp - createNested.cpp equals.cpp isNull.cpp iterator.cpp diff --git a/extras/tests/JsonArray/compare.cpp b/extras/tests/JsonArray/compare.cpp index 7198f6c2..ec49360d 100644 --- a/extras/tests/JsonArray/compare.cpp +++ b/extras/tests/JsonArray/compare.cpp @@ -43,15 +43,15 @@ TEST_CASE("Compare JsonArray with JsonArray") { } SECTION("Compare with identical array") { - JsonArray array1 = doc.createNestedArray(); + JsonArray array1 = doc.add(); array1.add(1); array1.add("hello"); - array1.createNestedObject(); + array1.add(); - JsonArray array2 = doc.createNestedArray(); + JsonArray array2 = doc.add(); array2.add(1); array2.add("hello"); - array2.createNestedObject(); + array2.add(); CHECK(array1 == array2); CHECK(array1 <= array2); @@ -62,15 +62,15 @@ TEST_CASE("Compare JsonArray with JsonArray") { } SECTION("Compare with different array") { - JsonArray array1 = doc.createNestedArray(); + JsonArray array1 = doc.add(); array1.add(1); array1.add("hello1"); - array1.createNestedObject(); + array1.add(); - JsonArray array2 = doc.createNestedArray(); + JsonArray array2 = doc.add(); array2.add(1); array2.add("hello2"); - array2.createNestedObject(); + array2.add(); CHECK(array1 != array2); CHECK_FALSE(array1 == array2); @@ -107,15 +107,15 @@ TEST_CASE("Compare JsonArray with JsonVariant") { } SECTION("Compare with identical array") { - JsonArray array = doc.createNestedArray(); + JsonArray array = doc.add(); array.add(1); array.add("hello"); - array.createNestedObject(); + array.add(); - JsonVariant variant = doc.createNestedArray(); + JsonVariant variant = doc.add(); variant.add(1); variant.add("hello"); - variant.createNestedObject(); + variant.add(); CHECK(array == variant); CHECK(array <= variant); @@ -133,15 +133,15 @@ TEST_CASE("Compare JsonArray with JsonVariant") { } SECTION("Compare with different array") { - JsonArray array = doc.createNestedArray(); + JsonArray array = doc.add(); array.add(1); array.add("hello1"); - array.createNestedObject(); + array.add(); - JsonVariant variant = doc.createNestedArray(); + JsonVariant variant = doc.add(); variant.add(1); variant.add("hello2"); - variant.createNestedObject(); + variant.add(); CHECK(array != variant); CHECK_FALSE(array == variant); @@ -199,15 +199,15 @@ TEST_CASE("Compare JsonArray with JsonVariantConst") { } SECTION("Compare with identical array") { - JsonArray array = doc.createNestedArray(); + JsonArray array = doc.add(); array.add(1); array.add("hello"); - array.createNestedObject(); + array.add(); - JsonArray array2 = doc.createNestedArray(); + JsonArray array2 = doc.add(); array2.add(1); array2.add("hello"); - array2.createNestedObject(); + array2.add(); JsonVariantConst variant = array2; CHECK(array == variant); @@ -226,15 +226,15 @@ TEST_CASE("Compare JsonArray with JsonVariantConst") { } SECTION("Compare with different array") { - JsonArray array = doc.createNestedArray(); + JsonArray array = doc.add(); array.add(1); array.add("hello1"); - array.createNestedObject(); + array.add(); - JsonArray array2 = doc.createNestedArray(); + JsonArray array2 = doc.add(); array2.add(1); array2.add("hello2"); - array2.createNestedObject(); + array2.add(); JsonVariantConst variant = array2; CHECK(array != variant); @@ -292,15 +292,15 @@ TEST_CASE("Compare JsonArray with JsonArrayConst") { } SECTION("Compare with identical array") { - JsonArray array1 = doc.createNestedArray(); + JsonArray array1 = doc.add(); array1.add(1); array1.add("hello"); - array1.createNestedObject(); + array1.add(); - JsonArray array2 = doc.createNestedArray(); + JsonArray array2 = doc.add(); array2.add(1); array2.add("hello"); - array2.createNestedObject(); + array2.add(); JsonArrayConst carray2 = array2; CHECK(array1 == carray2); @@ -319,15 +319,15 @@ TEST_CASE("Compare JsonArray with JsonArrayConst") { } SECTION("Compare with different array") { - JsonArray array1 = doc.createNestedArray(); + JsonArray array1 = doc.add(); array1.add(1); array1.add("hello1"); - array1.createNestedObject(); + array1.add(); - JsonArray array2 = doc.createNestedArray(); + JsonArray array2 = doc.add(); array2.add(1); array2.add("hello2"); - array2.createNestedObject(); + array2.add(); JsonArrayConst carray2 = array2; CHECK(array1 != carray2); @@ -387,16 +387,16 @@ TEST_CASE("Compare JsonArrayConst with JsonArrayConst") { } SECTION("Compare with identical array") { - JsonArray array1 = doc.createNestedArray(); + JsonArray array1 = doc.add(); array1.add(1); array1.add("hello"); - array1.createNestedObject(); + array1.add(); JsonArrayConst carray1 = array1; - JsonArray array2 = doc.createNestedArray(); + JsonArray array2 = doc.add(); array2.add(1); array2.add("hello"); - array2.createNestedObject(); + array2.add(); JsonArrayConst carray2 = array2; CHECK(carray1 == carray2); @@ -408,16 +408,16 @@ TEST_CASE("Compare JsonArrayConst with JsonArrayConst") { } SECTION("Compare with different array") { - JsonArray array1 = doc.createNestedArray(); + JsonArray array1 = doc.add(); array1.add(1); array1.add("hello1"); - array1.createNestedObject(); + array1.add(); JsonArrayConst carray1 = array1; - JsonArray array2 = doc.createNestedArray(); + JsonArray array2 = doc.add(); array2.add(1); array2.add("hello2"); - array2.createNestedObject(); + array2.add(); JsonArrayConst carray2 = array2; CHECK(carray1 != carray2); @@ -455,16 +455,16 @@ TEST_CASE("Compare JsonArrayConst with JsonVariant") { } SECTION("Compare with identical array") { - JsonArray array1 = doc.createNestedArray(); + JsonArray array1 = doc.add(); array1.add(1); array1.add("hello"); - array1.createNestedObject(); + array1.add(); JsonArrayConst carray1 = array1; - JsonArray array2 = doc.createNestedArray(); + JsonArray array2 = doc.add(); array2.add(1); array2.add("hello"); - array2.createNestedObject(); + array2.add(); JsonVariant variant2 = array2; CHECK(carray1 == variant2); @@ -483,16 +483,16 @@ TEST_CASE("Compare JsonArrayConst with JsonVariant") { } SECTION("Compare with different array") { - JsonArray array1 = doc.createNestedArray(); + JsonArray array1 = doc.add(); array1.add(1); array1.add("hello1"); - array1.createNestedObject(); + array1.add(); JsonArrayConst carray1 = array1; - JsonArray array2 = doc.createNestedArray(); + JsonArray array2 = doc.add(); array2.add(1); array2.add("hello2"); - array2.createNestedObject(); + array2.add(); JsonVariant variant2 = array2; CHECK(carray1 != variant2); diff --git a/extras/tests/JsonArray/createNested.cpp b/extras/tests/JsonArray/createNested.cpp deleted file mode 100644 index b930a18b..00000000 --- a/extras/tests/JsonArray/createNested.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON -// MIT License - -#include -#include - -TEST_CASE("JsonArray basics") { - JsonDocument doc; - JsonArray array = doc.to(); - - SECTION("CreateNestedArray") { - JsonArray arr = array.createNestedArray(); - REQUIRE(arr == array[0].as()); - } - - SECTION("CreateNestedObject") { - JsonObject obj = array.createNestedObject(); - REQUIRE(obj == array[0].as()); - } -} diff --git a/extras/tests/JsonArray/nesting.cpp b/extras/tests/JsonArray/nesting.cpp index 22ec70a3..23e5e963 100644 --- a/extras/tests/JsonArray/nesting.cpp +++ b/extras/tests/JsonArray/nesting.cpp @@ -24,12 +24,12 @@ TEST_CASE("JsonArray::nesting()") { } SECTION("returns 2 with nested array") { - arr.createNestedArray(); + arr.add(); REQUIRE(arr.nesting() == 2); } SECTION("returns 2 with nested object") { - arr.createNestedObject(); + arr.add(); REQUIRE(arr.nesting() == 2); } } diff --git a/extras/tests/JsonArray/unbound.cpp b/extras/tests/JsonArray/unbound.cpp index 0e21310b..396aab4d 100644 --- a/extras/tests/JsonArray/unbound.cpp +++ b/extras/tests/JsonArray/unbound.cpp @@ -19,14 +19,6 @@ TEST_CASE("Unbound JsonArray") { REQUIRE(0 == array.size()); } - SECTION("CreateNestedArrayFails") { - REQUIRE(array.createNestedArray().isNull()); - } - - SECTION("CreateNestedObjectFails") { - REQUIRE(array.createNestedObject().isNull()); - } - SECTION("PrintToWritesBrackets") { char buffer[32]; serializeJson(array, buffer, sizeof(buffer)); diff --git a/extras/tests/JsonDocument/CMakeLists.txt b/extras/tests/JsonDocument/CMakeLists.txt index 1a58d745..245c7bf8 100644 --- a/extras/tests/JsonDocument/CMakeLists.txt +++ b/extras/tests/JsonDocument/CMakeLists.txt @@ -9,7 +9,6 @@ add_executable(JsonDocumentTests compare.cpp constructor.cpp containsKey.cpp - createNested.cpp ElementProxy.cpp isNull.cpp issue1120.cpp diff --git a/extras/tests/JsonDocument/MemberProxy.cpp b/extras/tests/JsonDocument/MemberProxy.cpp index 68fd62fc..446a2338 100644 --- a/extras/tests/JsonDocument/MemberProxy.cpp +++ b/extras/tests/JsonDocument/MemberProxy.cpp @@ -281,38 +281,6 @@ TEST_CASE("MemberProxy cast to JsonVariant") { CHECK(doc.as() == "{\"hello\":\"toto\"}"); } -TEST_CASE("MemberProxy::createNestedArray()") { - JsonDocument doc; - JsonArray arr = doc["items"].createNestedArray(); - arr.add(42); - - CHECK(doc["items"][0][0] == 42); -} - -TEST_CASE("MemberProxy::createNestedArray(key)") { - JsonDocument doc; - JsonArray arr = doc["weather"].createNestedArray("temp"); - arr.add(42); - - CHECK(doc["weather"]["temp"][0] == 42); -} - -TEST_CASE("MemberProxy::createNestedObject()") { - JsonDocument doc; - JsonObject obj = doc["items"].createNestedObject(); - obj["value"] = 42; - - CHECK(doc["items"][0]["value"] == 42); -} - -TEST_CASE("MemberProxy::createNestedObject(key)") { - JsonDocument doc; - JsonObject obj = doc["status"].createNestedObject("weather"); - obj["temp"] = 42; - - CHECK(doc["status"]["weather"]["temp"] == 42); -} - TEST_CASE("Deduplicate keys") { SpyingAllocator spy; JsonDocument doc(&spy); diff --git a/extras/tests/JsonDocument/createNested.cpp b/extras/tests/JsonDocument/createNested.cpp deleted file mode 100644 index a5f56585..00000000 --- a/extras/tests/JsonDocument/createNested.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON -// MIT License - -#include -#include - -TEST_CASE("JsonDocument::createNestedArray()") { - JsonDocument doc; - - SECTION("promotes to array") { - doc.createNestedArray(); - - REQUIRE(doc.is()); - } -} - -TEST_CASE("JsonDocument::createNestedArray(key)") { - JsonDocument doc; - - SECTION("key is const char*") { - SECTION("promotes to object") { - doc.createNestedArray("hello"); - - REQUIRE(doc.is()); - } - } - - SECTION("key is std::string") { - SECTION("promotes to object") { - doc.createNestedArray(std::string("hello")); - - REQUIRE(doc.is()); - } - } -} - -TEST_CASE("JsonDocument::createNestedObject()") { - JsonDocument doc; - - SECTION("promotes to array") { - doc.createNestedObject(); - - REQUIRE(doc.is()); - } -} - -TEST_CASE("JsonDocument::createNestedObject(key)") { - JsonDocument doc; - - SECTION("key is const char*") { - SECTION("promotes to object") { - doc.createNestedObject("hello"); - - REQUIRE(doc.is()); - } - } - - SECTION("key is std::string") { - SECTION("promotes to object") { - doc.createNestedObject(std::string("hello")); - - REQUIRE(doc.is()); - } - } -} diff --git a/extras/tests/JsonObject/CMakeLists.txt b/extras/tests/JsonObject/CMakeLists.txt index 83a0bfc7..e28e7654 100644 --- a/extras/tests/JsonObject/CMakeLists.txt +++ b/extras/tests/JsonObject/CMakeLists.txt @@ -7,8 +7,6 @@ add_executable(JsonObjectTests compare.cpp containsKey.cpp copy.cpp - createNestedArray.cpp - createNestedObject.cpp equals.cpp invalid.cpp isNull.cpp diff --git a/extras/tests/JsonObject/compare.cpp b/extras/tests/JsonObject/compare.cpp index bb41c7d3..26483dd7 100644 --- a/extras/tests/JsonObject/compare.cpp +++ b/extras/tests/JsonObject/compare.cpp @@ -43,12 +43,12 @@ TEST_CASE("Compare JsonObject with JsonObject") { } SECTION("Compare with identical object") { - JsonObject object1 = doc.createNestedObject(); + JsonObject object1 = doc.add(); object1["a"] = 1; object1["b"] = "hello"; object1["c"][0] = false; - JsonObject object2 = doc.createNestedObject(); + JsonObject object2 = doc.add(); object2["a"] = 1; object2["b"] = "hello"; object2["c"][0] = false; @@ -62,12 +62,12 @@ TEST_CASE("Compare JsonObject with JsonObject") { } SECTION("Compare with different object") { - JsonObject object1 = doc.createNestedObject(); + JsonObject object1 = doc.add(); object1["a"] = 1; object1["b"] = "hello1"; object1["c"][0] = false; - JsonObject object2 = doc.createNestedObject(); + JsonObject object2 = doc.add(); object2["a"] = 1; object2["b"] = "hello2"; object2["c"][0] = false; @@ -107,12 +107,12 @@ TEST_CASE("Compare JsonObject with JsonVariant") { } SECTION("Compare with identical object") { - JsonObject object = doc.createNestedObject(); + JsonObject object = doc.add(); object["a"] = 1; object["b"] = "hello"; object["c"][0] = false; - JsonVariant variant = doc.createNestedObject(); + JsonVariant variant = doc.add(); variant["a"] = 1; variant["b"] = "hello"; variant["c"][0] = false; @@ -133,12 +133,12 @@ TEST_CASE("Compare JsonObject with JsonVariant") { } SECTION("Compare with different object") { - JsonObject object = doc.createNestedObject(); + JsonObject object = doc.add(); object["a"] = 1; object["b"] = "hello1"; object["c"][0] = false; - JsonVariant variant = doc.createNestedObject(); + JsonVariant variant = doc.add(); variant["a"] = 1; variant["b"] = "hello2"; variant["c"][0] = false; @@ -199,12 +199,12 @@ TEST_CASE("Compare JsonObject with JsonVariantConst") { } SECTION("Compare with identical object") { - JsonObject object = doc.createNestedObject(); + JsonObject object = doc.add(); object["a"] = 1; object["b"] = "hello"; object["c"][0] = false; - JsonObject object2 = doc.createNestedObject(); + JsonObject object2 = doc.add(); object2["a"] = 1; object2["b"] = "hello"; object2["c"][0] = false; @@ -226,12 +226,12 @@ TEST_CASE("Compare JsonObject with JsonVariantConst") { } SECTION("Compare with different object") { - JsonObject object = doc.createNestedObject(); + JsonObject object = doc.add(); object["a"] = 1; object["b"] = "hello1"; object["c"][0] = false; - JsonObject object2 = doc.createNestedObject(); + JsonObject object2 = doc.add(); object2["a"] = 1; object2["b"] = "hello2"; object2["c"][0] = false; @@ -292,12 +292,12 @@ TEST_CASE("Compare JsonObject with JsonObjectConst") { } SECTION("Compare with identical object") { - JsonObject object1 = doc.createNestedObject(); + JsonObject object1 = doc.add(); object1["a"] = 1; object1["b"] = "hello"; object1["c"][0] = false; - JsonObject object2 = doc.createNestedObject(); + JsonObject object2 = doc.add(); object2["a"] = 1; object2["b"] = "hello"; object2["c"][0] = false; @@ -319,12 +319,12 @@ TEST_CASE("Compare JsonObject with JsonObjectConst") { } SECTION("Compare with different object") { - JsonObject object1 = doc.createNestedObject(); + JsonObject object1 = doc.add(); object1["a"] = 1; object1["b"] = "hello1"; object1["c"][0] = false; - JsonObject object2 = doc.createNestedObject(); + JsonObject object2 = doc.add(); object2["a"] = 1; object2["b"] = "hello2"; object2["c"][0] = false; @@ -387,13 +387,13 @@ TEST_CASE("Compare JsonObjectConst with JsonObjectConst") { } SECTION("Compare with identical object") { - JsonObject object1 = doc.createNestedObject(); + JsonObject object1 = doc.add(); object1["a"] = 1; object1["b"] = "hello"; object1["c"][0] = false; JsonObjectConst carray1 = object1; - JsonObject object2 = doc.createNestedObject(); + JsonObject object2 = doc.add(); object2["a"] = 1; object2["b"] = "hello"; object2["c"][0] = false; @@ -408,13 +408,13 @@ TEST_CASE("Compare JsonObjectConst with JsonObjectConst") { } SECTION("Compare with different object") { - JsonObject object1 = doc.createNestedObject(); + JsonObject object1 = doc.add(); object1["a"] = 1; object1["b"] = "hello1"; object1["c"][0] = false; JsonObjectConst carray1 = object1; - JsonObject object2 = doc.createNestedObject(); + JsonObject object2 = doc.add(); object2["a"] = 1; object2["b"] = "hello2"; object2["c"][0] = false; @@ -455,13 +455,13 @@ TEST_CASE("Compare JsonObjectConst with JsonVariant") { } SECTION("Compare with identical object") { - JsonObject object1 = doc.createNestedObject(); + JsonObject object1 = doc.add(); object1["a"] = 1; object1["b"] = "hello"; object1["c"][0] = false; JsonObjectConst carray1 = object1; - JsonObject object2 = doc.createNestedObject(); + JsonObject object2 = doc.add(); object2["a"] = 1; object2["b"] = "hello"; object2["c"][0] = false; @@ -483,13 +483,13 @@ TEST_CASE("Compare JsonObjectConst with JsonVariant") { } SECTION("Compare with different object") { - JsonObject object1 = doc.createNestedObject(); + JsonObject object1 = doc.add(); object1["a"] = 1; object1["b"] = "hello1"; object1["c"][0] = false; JsonObjectConst carray1 = object1; - JsonObject object2 = doc.createNestedObject(); + JsonObject object2 = doc.add(); object2["a"] = 1; object2["b"] = "hello2"; object2["c"][0] = false; diff --git a/extras/tests/JsonObject/createNestedArray.cpp b/extras/tests/JsonObject/createNestedArray.cpp deleted file mode 100644 index f167508f..00000000 --- a/extras/tests/JsonObject/createNestedArray.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON -// MIT License - -#include -#include - -TEST_CASE("JsonObject::createNestedArray()") { - JsonDocument doc; - JsonObject obj = doc.to(); - - SECTION("key is a const char*") { - JsonArray arr = obj.createNestedArray("hello"); - REQUIRE(arr.isNull() == false); - } - -#ifdef HAS_VARIABLE_LENGTH_ARRAY - SECTION("key is a VLA") { - size_t i = 16; - char vla[i]; - strcpy(vla, "hello"); - - JsonArray arr = obj.createNestedArray(vla); - REQUIRE(arr.isNull() == false); - } -#endif -} diff --git a/extras/tests/JsonObject/createNestedObject.cpp b/extras/tests/JsonObject/createNestedObject.cpp deleted file mode 100644 index 85501e37..00000000 --- a/extras/tests/JsonObject/createNestedObject.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON -// MIT License - -#include -#include - -TEST_CASE("JsonObject::createNestedObject()") { - JsonDocument doc; - JsonObject obj = doc.to(); - - SECTION("key is a const char*") { - obj.createNestedObject("hello"); - } - -#ifdef HAS_VARIABLE_LENGTH_ARRAY - SECTION("key is a VLA") { - size_t i = 16; - char vla[i]; - strcpy(vla, "hello"); - - obj.createNestedObject(vla); - } -#endif -} diff --git a/extras/tests/JsonObject/invalid.cpp b/extras/tests/JsonObject/invalid.cpp index 0695b481..51f74d74 100644 --- a/extras/tests/JsonObject/invalid.cpp +++ b/extras/tests/JsonObject/invalid.cpp @@ -19,14 +19,6 @@ TEST_CASE("JsonObject::invalid()") { REQUIRE(0 == obj.size()); } - SECTION("CreateNestedArrayFails") { - REQUIRE(obj.createNestedArray("hello").isNull()); - } - - SECTION("CreateNestedObjectFails") { - REQUIRE(obj.createNestedObject("world").isNull()); - } - SECTION("serialize to 'null'") { char buffer[32]; serializeJson(obj, buffer, sizeof(buffer)); diff --git a/extras/tests/JsonObject/nesting.cpp b/extras/tests/JsonObject/nesting.cpp index 9992b0a0..6dc046de 100644 --- a/extras/tests/JsonObject/nesting.cpp +++ b/extras/tests/JsonObject/nesting.cpp @@ -24,12 +24,12 @@ TEST_CASE("JsonObject::nesting()") { } SECTION("returns 2 with nested array") { - obj.createNestedArray("nested"); + obj["nested"].to(); REQUIRE(obj.nesting() == 2); } SECTION("returns 2 with nested object") { - obj.createNestedObject("nested"); + obj["nested"].to(); REQUIRE(obj.nesting() == 2); } } diff --git a/extras/tests/JsonObject/std_string.cpp b/extras/tests/JsonObject/std_string.cpp index 0b2ba93b..6d275cfe 100644 --- a/extras/tests/JsonObject/std_string.cpp +++ b/extras/tests/JsonObject/std_string.cpp @@ -32,26 +32,6 @@ TEST_CASE("std::string") { REQUIRE(std::string("value") == obj[std::string("key")]); } - SECTION("createNestedObject()") { - JsonObject obj = doc.to(); - std::string key = "key"; - char json[64]; - obj.createNestedObject(key); - eraseString(key); - serializeJson(doc, json, sizeof(json)); - REQUIRE(std::string("{\"key\":{}}") == json); - } - - SECTION("createNestedArray()") { - JsonObject obj = doc.to(); - std::string key = "key"; - char json[64]; - obj.createNestedArray(key); - eraseString(key); - serializeJson(doc, json, sizeof(json)); - REQUIRE(std::string("{\"key\":[]}") == json); - } - SECTION("containsKey()") { char json[] = "{\"key\":\"value\"}"; deserializeJson(doc, json); diff --git a/extras/tests/JsonObject/subscript.cpp b/extras/tests/JsonObject/subscript.cpp index 9cf518c3..c8a91708 100644 --- a/extras/tests/JsonObject/subscript.cpp +++ b/extras/tests/JsonObject/subscript.cpp @@ -245,7 +245,7 @@ TEST_CASE("JsonObject::operator[]") { #endif SECTION("chain") { - obj.createNestedObject("hello")["world"] = 123; + obj["hello"]["world"] = 123; REQUIRE(123 == obj["hello"]["world"].as()); REQUIRE(true == obj["hello"]["world"].is()); diff --git a/extras/tests/JsonSerializer/JsonArray.cpp b/extras/tests/JsonSerializer/JsonArray.cpp index f5fa56e3..7933efaa 100644 --- a/extras/tests/JsonSerializer/JsonArray.cpp +++ b/extras/tests/JsonSerializer/JsonArray.cpp @@ -92,13 +92,13 @@ TEST_CASE("serializeJson(JsonArray)") { } SECTION("OneEmptyNestedArray") { - array.createNestedArray(); + array.add(); check(array, "[[]]"); } SECTION("OneEmptyNestedHash") { - array.createNestedObject(); + array.add(); check(array, "[{}]"); } diff --git a/extras/tests/JsonSerializer/JsonArrayPretty.cpp b/extras/tests/JsonSerializer/JsonArrayPretty.cpp index cb39943f..64ff1039 100644 --- a/extras/tests/JsonSerializer/JsonArrayPretty.cpp +++ b/extras/tests/JsonSerializer/JsonArrayPretty.cpp @@ -43,8 +43,8 @@ TEST_CASE("serializeJsonPretty(JsonArray)") { } SECTION("EmptyNestedArrays") { - array.createNestedArray(); - array.createNestedArray(); + array.add(); + array.add(); checkArray(array, "[\r\n" @@ -54,11 +54,11 @@ TEST_CASE("serializeJsonPretty(JsonArray)") { } SECTION("NestedArrays") { - JsonArray nested1 = array.createNestedArray(); + JsonArray nested1 = array.add(); nested1.add(1); nested1.add(2); - JsonObject nested2 = array.createNestedObject(); + JsonObject nested2 = array.add(); nested2["key"] = 3; checkArray(array, diff --git a/extras/tests/JsonSerializer/JsonObject.cpp b/extras/tests/JsonSerializer/JsonObject.cpp index da8cfac9..0735e69d 100644 --- a/extras/tests/JsonSerializer/JsonObject.cpp +++ b/extras/tests/JsonSerializer/JsonObject.cpp @@ -99,7 +99,7 @@ TEST_CASE("serializeJson(JsonObject)") { JsonDocument b; JsonDocument c; - obj.createNestedArray("a"); + obj["a"].to(); obj["b"] = b.to(); obj["c"] = c.to(); @@ -110,7 +110,7 @@ TEST_CASE("serializeJson(JsonObject)") { JsonDocument b; JsonDocument c; - obj.createNestedObject("a"); + obj["a"].to(); obj["b"] = b.to(); obj["c"] = c.to(); diff --git a/extras/tests/JsonSerializer/JsonObjectPretty.cpp b/extras/tests/JsonSerializer/JsonObjectPretty.cpp index d63840e4..953e8441 100644 --- a/extras/tests/JsonSerializer/JsonObjectPretty.cpp +++ b/extras/tests/JsonSerializer/JsonObjectPretty.cpp @@ -47,8 +47,8 @@ TEST_CASE("serializeJsonPretty(JsonObject)") { } SECTION("EmptyNestedContainers") { - obj.createNestedObject("key1"); - obj.createNestedArray("key2"); + obj["key1"].to(); + obj["key2"].to(); checkObjectPretty(obj, "{\r\n" @@ -58,10 +58,10 @@ TEST_CASE("serializeJsonPretty(JsonObject)") { } SECTION("NestedContainers") { - JsonObject nested1 = obj.createNestedObject("key1"); + JsonObject nested1 = obj["key1"].to(); nested1["a"] = 1; - JsonArray nested2 = obj.createNestedArray("key2"); + JsonArray nested2 = obj["key2"].to(); nested2.add(2); checkObjectPretty(obj, diff --git a/extras/tests/JsonVariant/CMakeLists.txt b/extras/tests/JsonVariant/CMakeLists.txt index 98cff9ea..6a541b3a 100644 --- a/extras/tests/JsonVariant/CMakeLists.txt +++ b/extras/tests/JsonVariant/CMakeLists.txt @@ -10,7 +10,6 @@ add_executable(JsonVariantTests containsKey.cpp converters.cpp copy.cpp - createNested.cpp is.cpp isnull.cpp misc.cpp diff --git a/extras/tests/JsonVariant/copy.cpp b/extras/tests/JsonVariant/copy.cpp index 6131e0d6..71635d35 100644 --- a/extras/tests/JsonVariant/copy.cpp +++ b/extras/tests/JsonVariant/copy.cpp @@ -16,7 +16,7 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { SECTION("stores JsonArray by copy") { JsonArray arr = doc2.to(); - JsonObject obj = arr.createNestedObject(); + JsonObject obj = arr.add(); obj["hello"] = "world"; var1.set(arr); @@ -27,7 +27,7 @@ TEST_CASE("JsonVariant::set(JsonVariant)") { SECTION("stores JsonObject by copy") { JsonObject obj = doc2.to(); - JsonArray arr = obj.createNestedArray("value"); + JsonArray arr = obj["value"].to(); arr.add(42); var1.set(obj); diff --git a/extras/tests/JsonVariant/createNested.cpp b/extras/tests/JsonVariant/createNested.cpp deleted file mode 100644 index d45c1af3..00000000 --- a/extras/tests/JsonVariant/createNested.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON -// MIT License - -#include -#include -#include - -TEST_CASE("JsonVariant::createNestedObject()") { - JsonDocument doc; - JsonVariant variant = doc.to(); - - SECTION("promotes to array") { - JsonObject obj = variant.createNestedObject(); - obj["value"] = 42; - - REQUIRE(variant.is() == true); - REQUIRE(variant[0]["value"] == 42); - REQUIRE(obj.isNull() == false); - } -} - -TEST_CASE("JsonVariant::createNestedArray()") { - JsonDocument doc; - JsonVariant variant = doc.to(); - - SECTION("promotes to array") { - JsonArray arr = variant.createNestedArray(); - - REQUIRE(variant.is() == true); - REQUIRE(arr.isNull() == false); - } -} - -TEST_CASE("JsonVariant::createNestedObject(key)") { - JsonDocument doc; - JsonVariant variant = doc.to(); - - SECTION("promotes to object") { - JsonObject obj = variant.createNestedObject("weather"); - obj["temp"] = 42; - - REQUIRE(variant.is() == true); - REQUIRE(variant["weather"]["temp"] == 42); - } -} - -TEST_CASE("JsonVariant::createNestedArray(key)") { - JsonDocument doc; - JsonVariant variant = doc.to(); - - SECTION("promotes to object") { - JsonArray arr = variant.createNestedArray("items"); - - REQUIRE(variant.is() == true); - REQUIRE(arr.isNull() == false); - } -} diff --git a/extras/tests/JsonVariant/subscript.cpp b/extras/tests/JsonVariant/subscript.cpp index 35bbc0b4..b1d9aa26 100644 --- a/extras/tests/JsonVariant/subscript.cpp +++ b/extras/tests/JsonVariant/subscript.cpp @@ -50,7 +50,7 @@ TEST_CASE("JsonVariant::operator[]") { } SECTION("set value in a nested object") { - array.createNestedObject(); + array.add(); var[0]["hello"] = "world"; diff --git a/extras/tests/Misc/unsigned_char.cpp b/extras/tests/Misc/unsigned_char.cpp index abfcda54..8b14ac2a 100644 --- a/extras/tests/Misc/unsigned_char.cpp +++ b/extras/tests/Misc/unsigned_char.cpp @@ -193,22 +193,6 @@ TEST_CASE("unsigned char[]") { REQUIRE(0 == obj.size()); } - - SECTION("createNestedArray()") { - unsigned char key[] = "hello"; - - JsonDocument doc; - JsonObject obj = doc.to(); - obj.createNestedArray(key); - } - - SECTION("createNestedObject()") { - unsigned char key[] = "hello"; - - JsonDocument doc; - JsonObject obj = doc.to(); - obj.createNestedObject(key); - } } SECTION("MemberProxy") { diff --git a/keywords.txt b/keywords.txt index 3deef02f..05d113d4 100644 --- a/keywords.txt +++ b/keywords.txt @@ -12,8 +12,6 @@ measureMsgPack KEYWORD2 # Methods add KEYWORD2 as KEYWORD2 -createNestedArray KEYWORD2 -createNestedObject KEYWORD2 get KEYWORD2 set KEYWORD2 to KEYWORD2 diff --git a/src/ArduinoJson/Array/JsonArray.hpp b/src/ArduinoJson/Array/JsonArray.hpp index 50044817..13418c86 100644 --- a/src/ArduinoJson/Array/JsonArray.hpp +++ b/src/ArduinoJson/Array/JsonArray.hpp @@ -130,16 +130,6 @@ class JsonArray : public detail::VariantOperators { return {*this, index}; } - // Creates an object and appends it to the array. - // https://arduinojson.org/v6/api/jsonarray/createnestedobject/ - FORCE_INLINE JsonObject createNestedObject() const; - - // Creates an array and appends it to the array. - // https://arduinojson.org/v6/api/jsonarray/createnestedarray/ - FORCE_INLINE JsonArray createNestedArray() const { - return add(); - } - operator JsonVariantConst() const { return JsonVariantConst(collectionToVariant(data_), resources_); } diff --git a/src/ArduinoJson/Array/JsonArrayImpl.hpp b/src/ArduinoJson/Array/JsonArrayImpl.hpp index c3165d01..50d59a66 100644 --- a/src/ArduinoJson/Array/JsonArrayImpl.hpp +++ b/src/ArduinoJson/Array/JsonArrayImpl.hpp @@ -7,26 +7,8 @@ #include #include -ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE - -inline JsonObject JsonArray::createNestedObject() const { - return add(); -} - -ARDUINOJSON_END_PUBLIC_NAMESPACE - ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE -template -inline JsonArray VariantRefBase::createNestedArray() const { - return add(); -} - -template -inline JsonObject VariantRefBase::createNestedObject() const { - return add(); -} - template inline ElementProxy VariantRefBase::operator[]( size_t index) const { diff --git a/src/ArduinoJson/Document/JsonDocument.hpp b/src/ArduinoJson/Document/JsonDocument.hpp index 4ca49576..dc182e14 100644 --- a/src/ArduinoJson/Document/JsonDocument.hpp +++ b/src/ArduinoJson/Document/JsonDocument.hpp @@ -152,46 +152,6 @@ class JsonDocument : public detail::VariantOperators { return getVariant().template to(); } - // Creates an array and appends it to the root array. - // https://arduinojson.org/v6/api/jsondocument/createnestedarray/ - JsonArray createNestedArray() { - return add(); - } - - // Creates an array and adds it to the root object. - // https://arduinojson.org/v6/api/jsondocument/createnestedarray/ - template - JsonArray createNestedArray(TChar* key) { - return operator[](key).template to(); - } - - // Creates an array and adds it to the root object. - // https://arduinojson.org/v6/api/jsondocument/createnestedarray/ - template - JsonArray createNestedArray(const TString& key) { - return operator[](key).template to(); - } - - // Creates an object and appends it to the root array. - // https://arduinojson.org/v6/api/jsondocument/createnestedobject/ - JsonObject createNestedObject() { - return add(); - } - - // Creates an object and adds it to the root object. - // https://arduinojson.org/v6/api/jsondocument/createnestedobject/ - template - JsonObject createNestedObject(TChar* key) { - return operator[](key).template to(); - } - - // Creates an object and adds it to the root object. - // https://arduinojson.org/v6/api/jsondocument/createnestedobject/ - template - JsonObject createNestedObject(const TString& key) { - return operator[](key).template to(); - } - // Returns true if the root object contains the specified key. // https://arduinojson.org/v6/api/jsondocument/containskey/ template diff --git a/src/ArduinoJson/Object/JsonObject.hpp b/src/ArduinoJson/Object/JsonObject.hpp index 8a460c6a..829ec893 100644 --- a/src/ArduinoJson/Object/JsonObject.hpp +++ b/src/ArduinoJson/Object/JsonObject.hpp @@ -166,30 +166,6 @@ class JsonObject : public detail::VariantOperators { resources_) != 0; } - // Creates an array and adds it to the object. - // https://arduinojson.org/v6/api/jsonobject/createnestedarray/ - template - FORCE_INLINE JsonArray createNestedArray(const TString& key) const; - - // Creates an array and adds it to the object. - // https://arduinojson.org/v6/api/jsonobject/createnestedarray/ - template - FORCE_INLINE JsonArray createNestedArray(TChar* key) const; - - // Creates an object and adds it to the object. - // https://arduinojson.org/v6/api/jsonobject/createnestedobject/ - template - JsonObject createNestedObject(const TString& key) const { - return operator[](key).template to(); - } - - // Creates an object and adds it to the object. - // https://arduinojson.org/v6/api/jsonobject/createnestedobject/ - template - JsonObject createNestedObject(TChar* key) const { - return operator[](key).template to(); - } - private: detail::ResourceManager* getResourceManager() const { return resources_; diff --git a/src/ArduinoJson/Object/JsonObjectImpl.hpp b/src/ArduinoJson/Object/JsonObjectImpl.hpp index 1a9c14e8..3684228e 100644 --- a/src/ArduinoJson/Object/JsonObjectImpl.hpp +++ b/src/ArduinoJson/Object/JsonObjectImpl.hpp @@ -7,49 +7,8 @@ #include #include -ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE - -template -inline JsonArray JsonObject::createNestedArray(const TString& key) const { - return operator[](key).template to(); -} - -template -inline JsonArray JsonObject::createNestedArray(TChar* key) const { - return operator[](key).template to(); -} - -ARDUINOJSON_END_PUBLIC_NAMESPACE - ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE -template -template -inline JsonArray VariantRefBase::createNestedArray( - const TString& key) const { - return operator[](key).template to(); -} - -template -template -inline JsonArray VariantRefBase::createNestedArray(TChar* key) const { - return operator[](key).template to(); -} - -template -template -inline JsonObject VariantRefBase::createNestedObject( - const TString& key) const { - return operator[](key).template to(); -} - -template -template -inline JsonObject VariantRefBase::createNestedObject( - TChar* key) const { - return operator[](key).template to(); -} - template template inline typename enable_if::value, bool>::type diff --git a/src/ArduinoJson/Variant/VariantRefBase.hpp b/src/ArduinoJson/Variant/VariantRefBase.hpp index ddcb5874..0138e403 100644 --- a/src/ArduinoJson/Variant/VariantRefBase.hpp +++ b/src/ArduinoJson/Variant/VariantRefBase.hpp @@ -191,14 +191,6 @@ class VariantRefBase : public VariantTag { getResourceManager()); } - // Creates an array and appends it to the array. - // https://arduinojson.org/v6/api/jsonvariant/createnestedarray/ - FORCE_INLINE JsonArray createNestedArray() const; - - // Creates an object and appends it to the array. - // https://arduinojson.org/v6/api/jsonvariant/createnestedobject/ - FORCE_INLINE JsonObject createNestedObject() const; - // Gets or sets an array element. // https://arduinojson.org/v6/api/jsonvariant/subscript/ FORCE_INLINE ElementProxy operator[](size_t index) const; @@ -229,26 +221,6 @@ class VariantRefBase : public VariantTag { MemberProxy>::type operator[](TChar* key) const; - // Creates an array and adds it to the object. - // https://arduinojson.org/v6/api/jsonvariant/createnestedarray/ - template - FORCE_INLINE JsonArray createNestedArray(const TString& key) const; - - // Creates an array and adds it to the object. - // https://arduinojson.org/v6/api/jsonvariant/createnestedarray/ - template - FORCE_INLINE JsonArray createNestedArray(TChar* key) const; - - // Creates an object and adds it to the object. - // https://arduinojson.org/v6/api/jsonvariant/createnestedobject/ - template - JsonObject createNestedObject(const TString& key) const; - - // Creates an object and adds it to the object. - // https://arduinojson.org/v6/api/jsonvariant/createnestedobject/ - template - JsonObject createNestedObject(TChar* key) const; - private: TDerived& derived() { return static_cast(*this);