{"action":"created","issue":{"url":"https://api.github.com/repos/nlohmann/json/issues/289","repository_url":"https://api.github.com/repos/nlohmann/json","labels_url":"https://api.github.com/repos/nlohmann/json/issues/289/labels{/name}","comments_url":"https://api.github.com/repos/nlohmann/json/issues/289/comments","events_url":"https://api.github.com/repos/nlohmann/json/issues/289/events","html_url":"https://github.com/nlohmann/json/issues/289","id":170123740,"number":289,"title":"Horribly inconsistent behavior between const/non-const reference in operator [] ()","user":{"login":"kawing-chiu","id":5235260,"avatar_url":"https://avatars.githubusercontent.com/u/5235260?v=3","gravatar_id":"","url":"https://api.github.com/users/kawing-chiu","html_url":"https://github.com/kawing-chiu","followers_url":"https://api.github.com/users/kawing-chiu/followers","following_url":"https://api.github.com/users/kawing-chiu/following{/other_user}","gists_url":"https://api.github.com/users/kawing-chiu/gists{/gist_id}","starred_url":"https://api.github.com/users/kawing-chiu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kawing-chiu/subscriptions","organizations_url":"https://api.github.com/users/kawing-chiu/orgs","repos_url":"https://api.github.com/users/kawing-chiu/repos","events_url":"https://api.github.com/users/kawing-chiu/events{/privacy}","received_events_url":"https://api.github.com/users/kawing-chiu/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nlohmann/json/labels/confirmed","name":"confirmed","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-08-09T09:40:53Z","updated_at":"2016-08-11T05:26:38Z","closed_at":null,"body":"Things like \r\n```cpp\r\nstd::string tag;\r\ntry {\r\n    tag = json[\"tag\"];\r\n} catch (const std::domain_error &e) {\r\n    //  handle it\r\n}\r\n```\r\nworks nicely and as expected. However, if `json` is a const reference, the above code will fail by **assertion**. Why is it designed like so? Shouldn't it be better and more consistent to at least throw a `domain_error` instead of fail by assertion? It took me more than one hour to debug this issue when I pass the above json by const reference to another function to extract data..."},"comment":{"url":"https://api.github.com/repos/nlohmann/json/issues/comments/239076619","html_url":"https://github.com/nlohmann/json/issues/289#issuecomment-239076619","issue_url":"https://api.github.com/repos/nlohmann/json/issues/289","id":239076619,"user":{"login":"nlohmann","id":159488,"avatar_url":"https://avatars.githubusercontent.com/u/159488?v=3","gravatar_id":"","url":"https://api.github.com/users/nlohmann","html_url":"https://github.com/nlohmann","followers_url":"https://api.github.com/users/nlohmann/followers","following_url":"https://api.github.com/users/nlohmann/following{/other_user}","gists_url":"https://api.github.com/users/nlohmann/gists{/gist_id}","starred_url":"https://api.github.com/users/nlohmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nlohmann/subscriptions","organizations_url":"https://api.github.com/users/nlohmann/orgs","repos_url":"https://api.github.com/users/nlohmann/repos","events_url":"https://api.github.com/users/nlohmann/events{/privacy}","received_events_url":"https://api.github.com/users/nlohmann/received_events","type":"User","site_admin":false},"created_at":"2016-08-11T05:26:38Z","updated_at":"2016-08-11T05:26:38Z","body":"@Dka8 The fix you describe is (more or less) the code of the [`at`](https://nlohmann.github.io/json/classnlohmann_1_1basic__json_a7ed92d56cb313b243c1917696ffdf074.html#a7ed92d56cb313b243c1917696ffdf074) function which offers checked access to the object. The `operator[]` function skips this check, just as `std::vector` or `std::map` do."}}
{"actor":{"display_login":"nlohmann"}}