-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
return json objects from functions #1172
Comments
This stores a copy
This modifies the original.
This modifies the version in j. |
@gregmarr that would not work, if you need to do it programatically, N-levels deep, which I need to :) I understand the value semantics and the copies, but that doesn't mean that internally each "node" can't track each other. Without it, you can't build and patch hierarchies easily, and it's unnatural. What I had to do is to make a pointer and find the element I want to patch using .at, and return it by reference. |
the other thing, it would be cool if there was an add or append API that specifically returns a json reference of the element that was just added |
I'm having a hard time visualizing what it is that you're trying to do. Maybe this:
|
I agree with @gregmarr in that I do not understand the issue yet. Could you try to describe your expected outcome and the difference to the actual behavior in more detail? |
Here is an example:
And the calling code, which creates a hierarchy but doesn't work because of the value semantics and copies:
I have to write to something like this, which does work, but is hacky:
But then I eventually wrote it as, which is better:
I still expect an API that appends and returns a reference directly though, something like:
|
As explanation: The API is the same as for a |
personally, I don't think that's not sensible, and I think it's inconsistent to have a push_back API, on something that might not be an array, but when used becomes an array, at which some of the other APIs wouldn't work, it's very unintuitive |
I don't understand: for arrays, |
not because it returns void, but because a json object has a vector API and non vector APIs on it, all together |
I see. That's this library's way to deal with JSON's different value types. When you only see a |
That is the equivalent of this:
or better
But is NOT the same as this:
Other than using
I would say the best way to write this would be something like (untested, but the syntax should be like this):
|
@itodirel Can you comment on |
I wrote something like that and it works for me, I'm not blocked, I just expected the node insertion to give me back the node I just inserted. Also thank you much for all your help and suggestions, it's very much appreciated. |
Thanks for checking back! We shall keep the |
Given a function like json json_add(json& j, std::string name), which given a json object, adds another object to it and returns it, I expect that if I call:
The last call to json_add would add another object on an existing one created before, to create a hierarchy, but instead nothing happens, is there a way achieve this programatically?
Expected:
The text was updated successfully, but these errors were encountered: