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

Function basics_wjson_example2

examples/src/basics_wexamples.cpp:135–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135void basics_wjson_example2()
136{
137 // Deserialize the booklist
138 std::wifstream is("./output/booklist2.json");
139 wjson booklist;
140 is >> booklist;
141
142 // Use a JSONPath expression to find
143 //
144 // (1) The authors of books that cost less than $12
145 wjson result = jsonpath::json_query(booklist, L"$[*][?(@.price < 12)].author");
146 std::wcout << L"(1) " << result << '\n';
147
148 // (2) The number of books
149 result = jsonpath::json_query(booklist, L"$.length");
150 std::wcout << L"(2) " << result << '\n';
151
152 // (3) The third book
153 result = jsonpath::json_query(booklist, L"$[2]");
154 std::wcout << L"(3) " << '\n' << pretty_print(result) << '\n';
155
156 // (4) The authors of books that were published in 2004
157 result = jsonpath::json_query(booklist, L"$[*][?(@.date =~ /2004.*?/)].author");
158 std::wcout << L"(4) " << result << '\n';
159
160 // (5) The titles of all books that have ratings
161 result = jsonpath::json_query(booklist, L"$[*][?(@.ratings)].title");
162 std::wcout << L"(5) " << result << '\n';
163}
164
165int main()
166{

Callers 1

mainFunction · 0.85

Calls 2

json_queryFunction · 0.85
pretty_printFunction · 0.85

Tested by

no test coverage detected