MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / expression_with_params_example

Function expression_with_params_example

examples/src/jmespath_examples.cpp:102–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102void expression_with_params_example() // since 1.3.0
103{
104 auto doc = json::parse(R"(
105{
106 "results": [
107 {
108 "name": "test1",
109 "uuid": "33bb9554-c616-42e6-a9c6-88d3bba4221c"
110 },
111 {
112 "name": "test2",
113 "uuid": "acde070d-8c4c-4f0d-9d8a-162843c10333"
114 }
115 ]
116}
117 )");
118
119 auto expr = jmespath::make_expression<json>("results[*].[name, uuid, $hostname]");
120
121 std::map<std::string,json> params = {{"hostname", "localhost"}};
122 auto result = expr.evaluate(doc, params);
123
124 auto options = jsoncons::json_options{}
125 .array_array_line_splits(jsoncons::line_split_kind::same_line);
126 std::cout << pretty_print(result) << "\n";
127}
128
129#if defined(_MSC_VER)
130

Callers 1

mainFunction · 0.85

Calls 4

parseFunction · 0.85
pretty_printFunction · 0.85
evaluateMethod · 0.45

Tested by

no test coverage detected