| 132 | #include <concurrent_vector.h> // microsoft PPL library |
| 133 | |
| 134 | void query_json_lines_in_parallel() |
| 135 | { |
| 136 | |
| 137 | std::vector<std::string> lines = { { |
| 138 | R"({"name": "Seattle", "state" : "WA"})", |
| 139 | R"({ "name": "New York", "state" : "NY" })", |
| 140 | R"({ "name": "Bellevue", "state" : "WA" })", |
| 141 | R"({ "name": "Olympia", "state" : "WA" })" |
| 142 | } }; |
| 143 | |
| 144 | auto expr = jsoncons::jmespath::make_expression<jsoncons::json>( |
| 145 | R"([@][?state=='WA'].name)"); |
| 146 | |
| 147 | concurrency::concurrent_vector<std::string> result; |
| 148 | |
| 149 | auto f = [&](const std::string& line) |
| 150 | { |
| 151 | const auto j = jsoncons::json::parse(line); |
| 152 | const auto r = expr.evaluate(j); |
| 153 | if (!r.empty()) |
| 154 | result.push_back(r.at(0).as<std::string>()); |
| 155 | }; |
| 156 | |
| 157 | std::for_each(std::execution::par, lines.begin(), lines.end(), f); |
| 158 | |
| 159 | for (const auto& s : result) |
| 160 | { |
| 161 | std::cout << s << "\n"; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | #endif |
| 166 | |