1#include <iostream>
2#include <nlohmann/json.hpp>
3
4using json = nlohmann::json;
5
6int main()
7{
8    // correct JSON pointers
9    json::json_pointer p1;
10    json::json_pointer p2("");
11    json::json_pointer p3("/");
12    json::json_pointer p4("//");
13    json::json_pointer p5("/foo/bar");
14    json::json_pointer p6("/foo/bar/-");
15    json::json_pointer p7("/foo/~0");
16    json::json_pointer p8("/foo/~1");
17
18    // error: JSON pointer does not begin with a slash
19    try
20    {
21        json::json_pointer p9("foo");
22    }
23    catch (json::parse_error& e)
24    {
25        std::cout << e.what() << '\n';
26    }
27
28    // error: JSON pointer uses escape symbol ~ not followed by 0 or 1
29    try
30    {
31        json::json_pointer p10("/foo/~");
32    }
33    catch (json::parse_error& e)
34    {
35        std::cout << e.what() << '\n';
36    }
37
38    // error: JSON pointer uses escape symbol ~ not followed by 0 or 1
39    try
40    {
41        json::json_pointer p11("/foo/~3");
42    }
43    catch (json::parse_error& e)
44    {
45        std::cout << e.what() << '\n';
46    }
47}
48