| 12 | namespace jsonpointer = jsoncons::jsonpointer; |
| 13 | |
| 14 | void jsonpointer_select_RFC6901() |
| 15 | { |
| 16 | // Example from RFC 6901 |
| 17 | auto j = json::parse(R"( |
| 18 | { |
| 19 | "foo": ["bar", "baz"], |
| 20 | "": 0, |
| 21 | "a/b": 1, |
| 22 | "c%d": 2, |
| 23 | "e^f": 3, |
| 24 | "g|h": 4, |
| 25 | "i\\j": 5, |
| 26 | "k\"l": 6, |
| 27 | " ": 7, |
| 28 | "m~n": 8 |
| 29 | } |
| 30 | )"); |
| 31 | |
| 32 | try |
| 33 | { |
| 34 | const json& result1 = jsonpointer::get(j, ""); |
| 35 | std::cout << "(1) " << result1 << '\n'; |
| 36 | const json& result2 = jsonpointer::get(j, "/foo"); |
| 37 | std::cout << "(2) " << result2 << '\n'; |
| 38 | const json& result3 = jsonpointer::get(j, "/foo/0"); |
| 39 | std::cout << "(3) " << result3 << '\n'; |
| 40 | const json& result4 = jsonpointer::get(j, "/"); |
| 41 | std::cout << "(4) " << result4 << '\n'; |
| 42 | const json& result5 = jsonpointer::get(j, "/a~1b"); |
| 43 | std::cout << "(5) " << result5 << '\n'; |
| 44 | const json& result6 = jsonpointer::get(j, "/c%d"); |
| 45 | std::cout << "(6) " << result6 << '\n'; |
| 46 | const json& result7 = jsonpointer::get(j, "/e^f"); |
| 47 | std::cout << "(7) " << result7 << '\n'; |
| 48 | const json& result8 = jsonpointer::get(j, "/g|h"); |
| 49 | std::cout << "(8) " << result8 << '\n'; |
| 50 | const json& result9 = jsonpointer::get(j, "/i\\j"); |
| 51 | std::cout << "(9) " << result9 << '\n'; |
| 52 | const json& result10 = jsonpointer::get(j, "/k\"l"); |
| 53 | std::cout << "(10) " << result10 << '\n'; |
| 54 | const json& result11 = jsonpointer::get(j, "/ "); |
| 55 | std::cout << "(11) " << result11 << '\n'; |
| 56 | const json& result12 = jsonpointer::get(j, "/m~0n"); |
| 57 | std::cout << "(12) " << result12 << '\n'; |
| 58 | } |
| 59 | catch (const jsonpointer::jsonpointer_error& e) |
| 60 | { |
| 61 | std::cerr << e.what() << '\n'; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | void jsonpointer_contains() |
| 66 | { |