{"action":"created","issue":{"url":"https://api.github.com/repos/miloyip/rapidjson/issues/366","labels_url":"https://api.github.com/repos/miloyip/rapidjson/issues/366/labels{/name}","comments_url":"https://api.github.com/repos/miloyip/rapidjson/issues/366/comments","events_url":"https://api.github.com/repos/miloyip/rapidjson/issues/366/events","html_url":"https://github.com/miloyip/rapidjson/issues/366","id":91075529,"number":366,"title":"How to insert document as node into another DOM tree?","user":{"login":"mloskot","id":80741,"avatar_url":"https://avatars.githubusercontent.com/u/80741?v=3","gravatar_id":"","url":"https://api.github.com/users/mloskot","html_url":"https://github.com/mloskot","followers_url":"https://api.github.com/users/mloskot/followers","following_url":"https://api.github.com/users/mloskot/following{/other_user}","gists_url":"https://api.github.com/users/mloskot/gists{/gist_id}","starred_url":"https://api.github.com/users/mloskot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mloskot/subscriptions","organizations_url":"https://api.github.com/users/mloskot/orgs","repos_url":"https://api.github.com/users/mloskot/repos","events_url":"https://api.github.com/users/mloskot/events{/privacy}","received_events_url":"https://api.github.com/users/mloskot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-25T21:04:14Z","updated_at":"2015-07-02T10:21:26Z","closed_at":null,"body":"Let's take two `Document` objects created by parsing the following .json files:\r\n* person.json\r\n```\r\n{ \"person\": { \"name\": { \"first\": \"Adam\", \"last\": \"Thomas\" } } }\r\n```\r\n* address.json\r\n```\r\n{ \"address\": { \"city\": \"Moscow\", \"street\": \"Quiet\" } }\r\n```\r\nWhat is the best way to insert the whole \"address\" node into the \"person\" DOM tree as a sibling node of the \"name\"?\r\n\r\nSo, the final document it reads\r\n```\r\n{\r\n  \"person\": {\r\n    \"name\": { \"first\": \"Adam\", \"last\": \"Thomas\" },\r\n    \"address\": { \"city\": \"Moscow\", \"street\": \"Quiet\" }\r\n  }\r\n}\r\n```\r\n\r\nHere is code that creates instances of the two DOM trees:\r\n```\r\nDocument person;\r\nperson.Parse(\"{\\\"person\\\":{\\\"name\\\":{\\\"first\\\":\\\"Adam\\\",\\\"last\\\":\\\"Thomas\\\"}}}\");\r\nRAPIDJSON_ASSERT(!person.HasParseError());\r\n\r\nDocument address;\r\naddress.Parse(\"{\\\"address\\\":{\\\"city\\\":\\\"Moscow\\\",\\\"street\\\":\\\"Quiet\\\"}}\");\r\nRAPIDJSON_ASSERT(!address.HasParseError());\r\n```\r\nfollowed by two possible solutions I was able to come up with:\r\n\r\n1. Requires to know name of the node in the source DOM - inconvenient, impractical:\r\n    ```\r\n    person[\"person\"].AddMember(\"address\", address[\"address\"], person.GetAllocator());\r\n    ```\r\n\r\n2. Requires use of iterators - not bad, but don't *feel* like suitable tool in this context:\r\n    ```\r\n    auto srcRoot = address.MemberBegin();\r\n    person[\"person\"].AddMember(srcRoot->name, srcRoot->value, person.GetAllocator());\r\n```\r\n\r\nIs there another, better way to achieve the same?"},"comment":{"url":"https://api.github.com/repos/miloyip/rapidjson/issues/comments/117991896","html_url":"https://github.com/miloyip/rapidjson/issues/366#issuecomment-117991896","issue_url":"https://api.github.com/repos/miloyip/rapidjson/issues/366","id":117991896,"user":{"login":"mloskot","id":80741,"avatar_url":"https://avatars.githubusercontent.com/u/80741?v=3","gravatar_id":"","url":"https://api.github.com/users/mloskot","html_url":"https://github.com/mloskot","followers_url":"https://api.github.com/users/mloskot/followers","following_url":"https://api.github.com/users/mloskot/following{/other_user}","gists_url":"https://api.github.com/users/mloskot/gists{/gist_id}","starred_url":"https://api.github.com/users/mloskot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mloskot/subscriptions","organizations_url":"https://api.github.com/users/mloskot/orgs","repos_url":"https://api.github.com/users/mloskot/repos","events_url":"https://api.github.com/users/mloskot/events{/privacy}","received_events_url":"https://api.github.com/users/mloskot/received_events","type":"User","site_admin":false},"created_at":"2015-07-02T10:21:26Z","updated_at":"2015-07-02T10:21:26Z","body":"@miloyip Thanks for the explanation and pointing at the possible issues, very informative.\r\n"}}