| 133 | } |
| 134 | |
| 135 | void 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 | |
| 165 | int main() |
| 166 | { |
no test coverage detected