Skip to content

Commit

Permalink
Example
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Feb 2, 2024
1 parent 54f8d09 commit 62be306
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions examples/src/jmespath_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,54 @@ void jmespath_expression_example()
std::cout << pretty_print(result) << "\n\n";
}

#if defined(_MSC_VER)

#include <execution>
#include <concurrent_vector.h> // microsoft PPL library

void query_json_lines_in_parallel()
{

std::vector<std::string> lines = { {
R"({"name": "Seattle", "state" : "WA"})",
R"({ "name": "New York", "state" : "NY" })",
R"({ "name": "Bellevue", "state" : "WA" })",
R"({ "name": "Olympia", "state" : "WA" })"
} };

auto expr = jsoncons::jmespath::make_expression<jsoncons::json>(
R"([@][?state=='WA'].name)");

concurrency::concurrent_vector<std::string> result;

auto f = [&](const std::string& line)
{
const auto j = jsoncons::json::parse(line);
const auto r = expr.evaluate(j);
if (!r.empty())
result.push_back(r.at(0).as<std::string>());
};

std::for_each(std::execution::par, lines.begin(), lines.end(), f);

for (const auto& s : result)
{
std::cout << s << "\n";
}
}

#endif

int main()
{
std::cout << "\nJMESPath examples\n\n";
search_example();
jmespath_expression_example();

#if defined(_MSC_VER)
query_json_lines_in_parallel();
#endif

std::cout << "\n";
}

0 comments on commit 62be306

Please sign in to comment.