Skip to content

Commit 3a892a8

Browse files
committed
Add flatten examples to doc
1 parent effd555 commit 3a892a8

File tree

5 files changed

+71
-71
lines changed

5 files changed

+71
-71
lines changed

doc/Examples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,7 @@ int main()
23942394

23952395
// for brevity
23962396
using jsoncons::json;
2397-
namespace jptr = jsoncons::jsonpointer;
2397+
namespace jsonpointer = jsoncons::jsonpointer;
23982398

23992399
int main()
24002400
{
@@ -2418,7 +2418,7 @@ int main()
24182418
}
24192419
)");
24202420

2421-
json result = jptr::flatten(input);
2421+
json result = jsonpointer::flatten(input);
24222422

24232423
std::cout << pretty_print(result) << "\n";
24242424
}

doc/ref/jsonpath/flatten.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ A flattened json object of JSONPath-value pairs
2929
3030
// for brevity
3131
using jsoncons::json;
32-
namespace jpath = jsoncons::jsonpath;
32+
namespace jsonpath = jsoncons::jsonpath;
3333
3434
int main()
3535
{
@@ -53,11 +53,11 @@ int main()
5353
}
5454
)");
5555
56-
json result = jpath::flatten(input);
56+
json result = jsonpath::flatten(input);
5757
5858
std::cout << pretty_print(result) << "\n";
5959
60-
json original = jpath::unflatten(result);
60+
json original = jsonpath::unflatten(result);
6161
assert(original == input);
6262
}
6363
```

doc/ref/jsonpointer/flatten.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ A flattened json object of JSONPointer-value pairs
2424
2525
// for brevity
2626
using jsoncons::json;
27-
namespace jptr = jsoncons::jsonpointer;
27+
namespace jsonpointer = jsoncons::jsonpointer;
2828
2929
int main()
3030
{
@@ -48,7 +48,7 @@ int main()
4848
}
4949
)");
5050
51-
json result = jptr::flatten(input);
51+
json result = jsonpointer::flatten(input);
5252
5353
std::cout << pretty_print(result) << "\n";
5454
}

examples/src/jsonpath_examples.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
// for brevity
1111
using jsoncons::json;
12-
namespace jpath = jsoncons::jsonpath;
12+
namespace jsonpath = jsoncons::jsonpath;
1313

1414
namespace {
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

Comments
 (0)