diff --git a/sdk/core/azure-core/test/ut/json_test.cpp b/sdk/core/azure-core/test/ut/json_test.cpp index cf9850f00..bc3d0185f 100644 --- a/sdk/core/azure-core/test/ut/json_test.cpp +++ b/sdk/core/azure-core/test/ut/json_test.cpp @@ -16,3 +16,31 @@ TEST(Json, create) EXPECT_EQ(expected, j.dump()); } + +TEST(Json, duplicateName) +{ + json jsonRoot = json::parse(R"({"KeyName": 1, "AnotherObject": {"KeyName": 2}})"); + int value = 0; + if (jsonRoot.contains("KeyName")) + { + value = jsonRoot["KeyName"].get(); + } + EXPECT_EQ(value, 1); + + jsonRoot = json::parse(R"({"AnotherObject": {"KeyName": 2}})"); + value = 0; + + // The nested KeyName property is considered not found, when at the root. + if (jsonRoot.contains("KeyName")) + { + value = jsonRoot["KeyName"].get(); + } + EXPECT_EQ(value, 0); + + // The nested KeyName property is considered found, when navigating to the nested object first. + if (jsonRoot["AnotherObject"].contains("KeyName")) + { + value = jsonRoot["AnotherObject"]["KeyName"].get(); + } + EXPECT_EQ(value, 2); +}