99
1010// for brevity
1111using jsoncons::json;
12- namespace jpath = jsoncons::jsonpath;
12+ namespace jsonpath = jsoncons::jsonpath;
1313
1414namespace {
1515
@@ -19,55 +19,55 @@ namespace {
1919 json booklist = json::parse (is);
2020
2121 // The authors of books that are cheaper than $10
22- json result1 = jpath ::json_query (booklist, " $.store.book[?(@.price < 10)].author" );
22+ json result1 = jsonpath ::json_query (booklist, " $.store.book[?(@.price < 10)].author" );
2323 std::cout << " (1) " << result1 << " \n " ;
2424
2525 // The number of books
26- json result2 = jpath ::json_query (booklist, " $..book.length" );
26+ json result2 = jsonpath ::json_query (booklist, " $..book.length" );
2727 std::cout << " (2) " << result2 << " \n " ;
2828
2929 // The third book
30- json result3 = jpath ::json_query (booklist, " $..book[2]" );
30+ json result3 = jsonpath ::json_query (booklist, " $..book[2]" );
3131 std::cout << " (3)\n " << pretty_print (result3) << " \n " ;
3232
3333 // All books whose author's name starts with Evelyn
34- json result4 = jpath ::json_query (booklist, " $.store.book[?(@.author =~ /Evelyn.*?/)]" );
34+ json result4 = jsonpath ::json_query (booklist, " $.store.book[?(@.author =~ /Evelyn.*?/)]" );
3535 std::cout << " (4)\n " << pretty_print (result4) << " \n " ;
3636
3737 // The titles of all books that have isbn number
38- json result5 = jpath ::json_query (booklist, " $..book[?(@.isbn)].title" );
38+ json result5 = jsonpath ::json_query (booklist, " $..book[?(@.isbn)].title" );
3939 std::cout << " (5) " << result5 << " \n " ;
4040
4141 // All authors and titles of books
42- json result6 = jpath ::json_query (booklist, " $['store']['book']..['author','title']" );
42+ json result6 = jsonpath ::json_query (booklist, " $['store']['book']..['author','title']" );
4343 std::cout << " (6)\n " << pretty_print (result6) << " \n " ;
4444
4545 // Union of two ranges of book titles
46- json result7 = jpath ::json_query (booklist, " $..book[1:2,2:4].title" );
46+ json result7 = jsonpath ::json_query (booklist, " $..book[1:2,2:4].title" );
4747 std::cout << " (7)\n " << pretty_print (result7) << " \n " ;
4848
4949 // Union of a subset of book titles identified by index
50- json result8 = jpath ::json_query (booklist, " $.store[book[0].title,book[1].title,book[3].title]" );
50+ json result8 = jsonpath ::json_query (booklist, " $.store[book[0].title,book[1].title,book[3].title]" );
5151 std::cout << " (8)\n " << pretty_print (result8) << " \n " ;
5252
5353 // Union of third book title and all book titles with price > 10
54- json result9 = jpath ::json_query (booklist, " $.store[book[3].title,book[?(@.price > 10)].title]" );
54+ json result9 = jsonpath ::json_query (booklist, " $.store[book[3].title,book[?(@.price > 10)].title]" );
5555 std::cout << " (9)\n " << pretty_print (result9) << " \n " ;
5656
5757 // Intersection of book titles with category fiction and price < 15
58- json result10 = jpath ::json_query (booklist, " $.store.book[?(@.category == 'fiction')][?(@.price < 15)].title" );
58+ json result10 = jsonpath ::json_query (booklist, " $.store.book[?(@.category == 'fiction')][?(@.price < 15)].title" );
5959 std::cout << " (10)\n " << pretty_print (result10) << " \n " ;
6060
6161 // Normalized path expressions
62- json result11 = jpath ::json_query (booklist, " $.store.book[?(@.author =~ /Evelyn.*?/)]" , jpath ::result_type::path);
62+ json result11 = jsonpath ::json_query (booklist, " $.store.book[?(@.author =~ /Evelyn.*?/)]" , jsonpath ::result_type::path);
6363 std::cout << " (11)\n " << pretty_print (result11) << " \n " ;
6464
6565 // All titles whose author's second name is 'Waugh'
66- json result12 = jpath ::json_query (booklist," $.store.book[?(tokenize(@.author,'\\\\ s+')[1] == 'Waugh')].title" );
66+ json result12 = jsonpath ::json_query (booklist," $.store.book[?(tokenize(@.author,'\\\\ s+')[1] == 'Waugh')].title" );
6767 std::cout << " (12)\n " << result12 << " \n " ;
6868
6969 // All keys in the second book
70- json result13 = jpath ::json_query (booklist," keys($.store.book[1])[*]" );
70+ json result13 = jsonpath ::json_query (booklist," keys($.store.book[1])[*]" );
7171 std::cout << " (13)\n " << result13 << " \n " ;
7272 }
7373
@@ -76,7 +76,7 @@ namespace {
7676 std::ifstream is (" ./input/booklist.json" );
7777 json booklist = json::parse (is);
7878
79- jpath ::json_replace (booklist," $.store.book[?(@.isbn == '0-553-21311-3')].price" ,10.0 );
79+ jsonpath ::json_replace (booklist," $.store.book[?(@.isbn == '0-553-21311-3')].price" ,10.0 );
8080 std::cout << pretty_print (booklist) << " \n " ;
8181 }
8282
@@ -106,7 +106,7 @@ namespace {
106106
107107 std::cout << (" 1\n " ) << pretty_print (j) << " \n " ;
108108
109- jpath ::json_replace (j," $..book[?(@.price==31.96)].price" , 30.9 );
109+ jsonpath ::json_replace (j," $..book[?(@.price==31.96)].price" , 30.9 );
110110
111111 std::cout << (" 2\n " ) << pretty_print (j) << " \n " ;
112112 }
@@ -197,15 +197,15 @@ namespace {
197197 )" );
198198
199199 // Find all arrays of elements where result.length is 4
200- json result1 = jpath ::json_query (j," $..[?(@.result.length == 4)].result" );
200+ json result1 = jsonpath ::json_query (j," $..[?(@.result.length == 4)].result" );
201201 std::cout << " (1) " << result1 << " \n " ;
202202
203203 // Find array of elements that has id 10 and result.length is 4
204- json result2 = jpath ::json_query (j," $..[?(@.id == 10)]..[?(@.result.length == 4)].result" );
204+ json result2 = jsonpath ::json_query (j," $..[?(@.id == 10)]..[?(@.result.length == 4)].result" );
205205 std::cout << " (2) " << result2 << " \n " ;
206206
207207 // Find all arrays of elements where result.length is 4 and that have value 3
208- json result3 = jpath ::json_query (j," $..[?(@.result.length == 4 && (@.result[0] == 3 || @.result[1] == 3 || @.result[2] == 3 || @.result[3] == 3))].result" );
208+ json result3 = jsonpath ::json_query (j," $..[?(@.result.length == 4 && (@.result[0] == 3 || @.result[1] == 3 || @.result[2] == 3 || @.result[3] == 3))].result" );
209209 std::cout << " (3) " << result3 << " \n " ;
210210 }
211211
@@ -234,7 +234,7 @@ namespace {
234234 } )" );
235235
236236 std::string path = " $..[firstName,address.city]" ;
237- json result = jpath ::json_query (root,path);
237+ json result = jsonpath ::json_query (root,path);
238238
239239 std::cout << result << " \n " ;
240240 }
@@ -261,11 +261,11 @@ namespace {
261261 }
262262 )" );
263263
264- json result = jpath ::flatten (input);
264+ json result = jsonpath ::flatten (input);
265265
266266 std::cout << pretty_print (result) << " \n " ;
267267
268- json original = jpath ::unflatten (result);
268+ json original = jsonpath ::unflatten (result);
269269 assert (original == input);
270270 }
271271
0 commit comments