Skip to content

Instantly share code, notes, and snippets.

@daminetreg
Created December 12, 2020 10:17
Show Gist options
  • Save daminetreg/5a9fd23dcf63cc9f2cc55cae2451ef7e to your computer and use it in GitHub Desktop.
Save daminetreg/5a9fd23dcf63cc9f2cc55cae2451ef7e to your computer and use it in GitHub Desktop.
#include <iostream>
#include <pre/json/from_json.hpp>
struct tool {
std::string url;
std::string sha1;
std::string root;
};
BOOST_FUSION_ADAPT_STRUCT(tool, url, sha1, root);
int main(int argc, char** argv) {
std::string jsontoparse = R"(
{
"polly": {
"all": {
"universal": {
"url": "https://github.com/nxxm/polly/archive/21f329fa47f776440ba47f3e90219bad18ff820b.zip",
"sha1": "15f806c905f71176ab7ff72996f433a9b3e261d9",
"root": "polly-21f329fa47f776440ba47f3e90219bad18ff820b"
}
}
},
"hunter": {
"all": {
"universal": {
"url": "https://github.com/nxxm/hunter/archive/4d2df6b5f29c204b4b03cf4da85db7f491af57c4.zip",
"sha1": "759eb1f422c257cba613f871fa64af461d35ae34",
"root": "hunter-4d2df6b5f29c204b4b03cf4da85db7f491af57c4/"
}
}
}
}
)";
using platforms = std::map<std::string, std::map<std::string, tool>>;
using all_tools = std::map<std::string, platforms>;
auto yougetthem = pre::json::from_json<all_tools>(jsontoparse);
for (auto& platform : yougetthem) {
std::cout << platform.first << " -- ";
for ( auto tool_for_platform : platform.second) {
std::cout << "platform : " << tool_for_platform.first << " : " << tool_for_platform.second["universal"].url << std::endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment