-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can two json objects be concatenated? #1019
Comments
https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp#L14797-L14816
|
Fantastic to find |
There's not a lot to gain by adding another way to do this as there are only a few characters difference between the two. I personally like the Python mantra: "There should be one -- and preferably only one -- obvious way to do it.". C++ doesn't always live up to this, but it's a nice rule in general. But, I'd also expect addition operations to have familiar properties like commutivity (eg, "j1+j2" and "j2+j1" should give the same result, but for JSON they wouldn't!). Sure, std::string has a non-commutative "+" but that doesn't mean we should give up on that goal. |
Does this update method work with merging recursively? Merging j1 and j2 (concatenating, updating) I would expect to get:
I’m not sure if any changes to merge occurred since 3.3.0 .. but in this older version when merging only the top level properties are concatenated.. namely, if there is a duplicate to be merged (albeit with different subtree values) the previous property is being replaced by the duplicate property in the other j object. Essentially merging j1.update(j2) creates this:
which removes the previous attributes values.
gives the output:
|
@DolphinDream There is now a recursive parameter to the |
Yeah.. i just noticed "Added merge_objects parameter in 3.10.4” .. which explains my 3.3.0 issue :) |
for example:
The text was updated successfully, but these errors were encountered: