Skip to content
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

Sending to a function a reference to a sub-branch #2200

Closed
tawmoto opened this issue Jun 18, 2020 · 2 comments
Closed

Sending to a function a reference to a sub-branch #2200

tawmoto opened this issue Jun 18, 2020 · 2 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@tawmoto
Copy link

tawmoto commented Jun 18, 2020

Hi,

I am trying to send a reference to sub-branch (I don't know the exact name for this, sorry) of a json to a function. This is because I have a huge json and I don't want to split it in functions.

void func(json &j)
{
    j["branch"] = "abc";
}

int main()
{
json j2 = {{"pi", 3.141},
               {"happy", true}};

func(j2["tree"]);
}

and I expect

{
    "happy": true,
    "pi": 3.141,
    "tree": {
        "branch": "abc"
    }

Is this the proper way of doing it?
Thank you

@nlohmann
Copy link
Owner

Yes, passing a reference is the way to go.

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Jun 18, 2020
@tawmoto
Copy link
Author

tawmoto commented Jun 18, 2020

Yes, passing a reference is the way to go.

Thank you, as I use it every day I am amazed how fantastic this library is!

@tawmoto tawmoto closed this as completed Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants