From d336129b46e567ec58ab45bebaab7b094d43c6c1 Mon Sep 17 00:00:00 2001 From: Swastik Bose Date: Thu, 21 May 2026 19:58:26 +0530 Subject: [PATCH 1/3] added fix for issue 4813 Signed-off-by: VasuBhakt --- include/nlohmann/json.hpp | 3 +++ single_include/nlohmann/json.hpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 47d5c51ff3..5e44e8d709 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3497,6 +3497,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec if (it2 != m_data.m_value.object->end()) { it2->second.update(it.value(), true); +#if JSON_DIAGNOSTICS + it2->second.set_parents(); +#endif continue; } } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 2e16ad5b9e..d2165e8ef5 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -24000,6 +24000,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec if (it2 != m_data.m_value.object->end()) { it2->second.update(it.value(), true); +#if JSON_DIAGNOSTICS + it2->second.set_parents(); +#endif continue; } } From 18cba2078d84743a23c8a7045489ecd1cbe5913c Mon Sep 17 00:00:00 2001 From: Swastik Bose Date: Fri, 22 May 2026 12:00:29 +0530 Subject: [PATCH 2/3] added regression test for 4813 Signed-off-by: VasuBhakt --- tests/src/unit-regression2.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index f60b4a277c..99739fb124 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -1330,3 +1330,16 @@ TEST_CASE("regression test #5122 - nlohmann::ordered_map move-assignment transfe } DOCTEST_CLANG_SUPPRESS_WARNING_POP + +TEST_CASE("regression test #4813 - update() with merge_objects=true triggers JSON_ASSERT with JSON_DIAGNOSTICS") +{ + // https://github.com/nlohmann/json/issues/4813 + nlohmann::ordered_json j1 = {{"numbers", {{"one", 1}}}}; + nlohmann::ordered_json const j2 = {{"numbers", {{"two", 2}}}, {"string", "t"}}; + CHECK_NOTHROW(j1.update(j2, true)); + CHECK(j1["numbers"]["one"] == 1); + CHECK(j1["numbers"]["two"] == 2); + CHECK(j1["string"] == "t"); +} + + From f85e9b6bddffc66184525c2ff21bdf291a3ad682 Mon Sep 17 00:00:00 2001 From: Swastik Bose Date: Fri, 22 May 2026 13:03:53 +0530 Subject: [PATCH 3/3] moved test from unit-regression2 to unit-diagnostics Signed-off-by: VasuBhakt --- tests/src/unit-diagnostics.cpp | 12 ++++++++++++ tests/src/unit-regression2.cpp | 13 ------------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/src/unit-diagnostics.cpp b/tests/src/unit-diagnostics.cpp index c5feafe442..1e8ed6aa3b 100644 --- a/tests/src/unit-diagnostics.cpp +++ b/tests/src/unit-diagnostics.cpp @@ -262,4 +262,16 @@ TEST_CASE("Regression tests for extended diagnostics") CHECK(k.dump() == "{\"prop1\":\"prop1_value\",\"root\":\"root_str\"}"); } + + SECTION("Regression test for issue #4813 - update() with merge_objects=true triggers JSON_ASSERT with JSON_DIAGNOSTICS") + { + // https://github.com/nlohmann/json/issues/4813 + nlohmann::ordered_json j1 = {{"numbers", {{"one", 1}}}}; + nlohmann::ordered_json const j2 = {{"numbers", {{"two", 2}}}, {"string", "t"}}; + CHECK_NOTHROW(j1.update(j2, true)); + CHECK(j1["numbers"]["one"] == 1); + CHECK(j1["numbers"]["two"] == 2); + CHECK(j1["string"] == "t"); + } } + diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index 99739fb124..f60b4a277c 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -1330,16 +1330,3 @@ TEST_CASE("regression test #5122 - nlohmann::ordered_map move-assignment transfe } DOCTEST_CLANG_SUPPRESS_WARNING_POP - -TEST_CASE("regression test #4813 - update() with merge_objects=true triggers JSON_ASSERT with JSON_DIAGNOSTICS") -{ - // https://github.com/nlohmann/json/issues/4813 - nlohmann::ordered_json j1 = {{"numbers", {{"one", 1}}}}; - nlohmann::ordered_json const j2 = {{"numbers", {{"two", 2}}}, {"string", "t"}}; - CHECK_NOTHROW(j1.update(j2, true)); - CHECK(j1["numbers"]["one"] == 1); - CHECK(j1["numbers"]["two"] == 2); - CHECK(j1["string"] == "t"); -} - -