Fix: update() parent pointers not updated after recursive merge with JSON_DIAGNOSTICS#5187
Merged
Conversation
nlohmann
requested changes
May 21, 2026
Owner
nlohmann
left a comment
There was a problem hiding this comment.
Can you please add a regression test (best the example from #4813) to unit-regression2.cpp?
Contributor
Author
|
sure, working on it. |
Signed-off-by: VasuBhakt <cpswastik31@gmail.com>
Signed-off-by: VasuBhakt <cpswastik31@gmail.com>
Contributor
Author
|
added the regression test @nlohmann, please review it |
nlohmann
reviewed
May 22, 2026
nlohmann
reviewed
May 22, 2026
Signed-off-by: VasuBhakt <cpswastik31@gmail.com>
nlohmann
reviewed
May 22, 2026
Contributor
Author
|
Thanks a lot @nlohmann! You have been very patient and responsive throughout the review process. Really appreciate the guidance! |
Owner
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Fixes #4813
Overview
Added a set_parents() call under
#if JSON_DIAGNOSTICSin theupdate()iterator overload after a recursive merge.When update() is called with merge_objects=true, nested objects are recursively merged via
it2->second.update(it.value(), true). After this recursive call, the child nodes inside the merged object have stalem_parent pointers, causing the parent consistency assertion to fire whenJSON_DIAGNOSTICS=1is enabled. Callingset_parents()after the recursive merge walks the subtree and fixes all parent pointers correctly.Changes
include/nlohmann/json.hpp— 3 line fix inupdate()iterator overloadsingle_include/nlohmann/json.hpp— regenerated viamake amalgamateThe changes were tested locally which gave the results:
make amalgamate.