Skip to content

return json objects from functions #1172

Description

@itodirel

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:

json j;
json_add(j, "1");
json j2 = json_add(j, "2");
json_add(j2, "3");

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?

json j = 
{
    { "filename", "file.cpp" }
};
json j2;
j2["prop"] = "1";

j["j2"] = j2;

j2["prop2"] = "2"; // after adding j2 to j, their reference is lost, so further updates to j2 does nothing

Expected:

{
  "filename": "file.cpp",
  "j2": {
    "prop": "1"
    "prop2": "2"
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions