{"action":"created","issue":{"url":"https://api.github.com/repos/nlohmann/json/issues/83","labels_url":"https://api.github.com/repos/nlohmann/json/issues/83/labels{/name}","comments_url":"https://api.github.com/repos/nlohmann/json/issues/83/comments","events_url":"https://api.github.com/repos/nlohmann/json/issues/83/events","html_url":"https://github.com/nlohmann/json/issues/83","id":85636191,"number":83,"title":"range based for loop for objects","user":{"login":"nickdesaulniers","id":1823839,"avatar_url":"https://avatars.githubusercontent.com/u/1823839?v=3","gravatar_id":"","url":"https://api.github.com/users/nickdesaulniers","html_url":"https://github.com/nickdesaulniers","followers_url":"https://api.github.com/users/nickdesaulniers/followers","following_url":"https://api.github.com/users/nickdesaulniers/following{/other_user}","gists_url":"https://api.github.com/users/nickdesaulniers/gists{/gist_id}","starred_url":"https://api.github.com/users/nickdesaulniers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickdesaulniers/subscriptions","organizations_url":"https://api.github.com/users/nickdesaulniers/orgs","repos_url":"https://api.github.com/users/nickdesaulniers/repos","events_url":"https://api.github.com/users/nickdesaulniers/events{/privacy}","received_events_url":"https://api.github.com/users/nickdesaulniers/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nlohmann/json/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/nlohmann/json/milestones/1","html_url":"https://github.com/nlohmann/json/milestones/Release%201.0.0-rc1","labels_url":"https://api.github.com/repos/nlohmann/json/milestones/1/labels","id":1189739,"number":1,"title":"Release 1.0.0-rc1","description":"The 1.0.0 release should be the first \"official\" release after the initial announcement of the class in January 2015 via reddit (\"0.1.0\") and a heavily overworked second version (\"0.2.0\") in February. By switching to official releases, I would like to make the class evolution and feature set more predictable. The times of frequent API changes are over.\r\n\r\nThis milestone collects issues that should be finished before a release can be made.","creator":{"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},"open_issues":1,"closed_issues":5,"state":"open","created_at":"2015-07-01T21:13:03Z","updated_at":"2015-07-26T18:11:28Z","due_on":null,"closed_at":null},"comments":12,"created_at":"2015-06-05T21:23:59Z","updated_at":"2015-07-27T16:00:47Z","closed_at":null,"body":"Note that the readme recommends this syntax for iterating key/value pairs of an object:\r\n```c++\r\nfor (json::iterator it = o.begin(); it != o.end(); ++it) {\r\n  std::cout << it.key() << \" : \" << it.value() << \"\\n\";\r\n}\r\n```\r\n\r\nIf we try to iterate an nlohmann::json object using a range based for, we only seem to get the value:\r\n\r\n```c++\r\n// clang++ example.cpp -std=c++11 -I lib/\r\n#include \"json.hpp\"\r\nint main () {\r\n  using nlohmann::json;\r\n  json j = json::parse(\"{ \\\"hello\\\": \\\"world\\\", \\\"name\\\": \\\"Nick\\\" }\");\r\n  for (json::iterator it = j.begin(); it != j.end(); ++it) {\r\n    std::cout << it.key() << \" : \" << it.value() << \"\\n\";\r\n  }\r\n  for (auto pair : j) {\r\n    std::cout << pair << \"\\n\";\r\n    // std::cout << pair.first << \" : \" << pair.second << \"\\n\";\r\n  }\r\n\r\n  std::map<std::string, std::string> map { {\"hello\", \"world\"}, {\"name\", \"Nick\"} };\r\n  for (auto& pair: map) {\r\n    std::cout << pair.first << \" : \" << pair.second << \"\\n\";\r\n    //std::cout << pair << \"\\n\";\r\n  }\r\n}\r\n```\r\nprints:\r\n```\r\nhello : \"world\"\r\nname : \"Nick\"\r\n\"world\"\r\n\"Nick\"\r\nhello : world\r\nname : Nick\r\n```\r\n\r\nUsing [some fancyness](http://stackoverflow.com/a/6963910/1027966), it should be possible to provide an API similar to std::map et al for iterating key value pairs of an object."},"comment":{"url":"https://api.github.com/repos/nlohmann/json/issues/comments/125255446","html_url":"https://github.com/nlohmann/json/issues/83#issuecomment-125255446","issue_url":"https://api.github.com/repos/nlohmann/json/issues/83","id":125255446,"user":{"login":"nickdesaulniers","id":1823839,"avatar_url":"https://avatars.githubusercontent.com/u/1823839?v=3","gravatar_id":"","url":"https://api.github.com/users/nickdesaulniers","html_url":"https://github.com/nickdesaulniers","followers_url":"https://api.github.com/users/nickdesaulniers/followers","following_url":"https://api.github.com/users/nickdesaulniers/following{/other_user}","gists_url":"https://api.github.com/users/nickdesaulniers/gists{/gist_id}","starred_url":"https://api.github.com/users/nickdesaulniers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickdesaulniers/subscriptions","organizations_url":"https://api.github.com/users/nickdesaulniers/orgs","repos_url":"https://api.github.com/users/nickdesaulniers/repos","events_url":"https://api.github.com/users/nickdesaulniers/events{/privacy}","received_events_url":"https://api.github.com/users/nickdesaulniers/received_events","type":"User","site_admin":false},"created_at":"2015-07-27T16:00:47Z","updated_at":"2015-07-27T16:00:47Z","body":"I think something is wrong with the output? The value of the second and third element should be \"bar\" and \"baz\" respectively.  Assuming simple copy+paste error, this looks great!  Nice job!\r\n\r\nMaybe a separate issue we can discuss in another ticket; keys in JSON are not sorted, but ordered based on definition.  This becomes apparent when iterating keys of an object."}}