json_pointer.cpp
Go to the documentation of this file.
00001 #include <json.hpp>
00002 
00003 using json = nlohmann::json;
00004 
00005 int main()
00006 {
00007     // correct JSON pointers
00008     json::json_pointer p1;
00009     json::json_pointer p2("");
00010     json::json_pointer p3("/");
00011     json::json_pointer p4("//");
00012     json::json_pointer p5("/foo/bar");
00013     json::json_pointer p6("/foo/bar/-");
00014     json::json_pointer p7("/foo/~0");
00015     json::json_pointer p8("/foo/~1");
00016 
00017     // error: JSON pointer does not begin with a slash
00018     try
00019     {
00020         json::json_pointer p9("foo");
00021     }
00022     catch (std::domain_error& e)
00023     {
00024         std::cout << "domain_error: " << e.what() << '\n';
00025     }
00026 
00027     // error: JSON pointer uses escape symbol ~ not followed by 0 or 1
00028     try
00029     {
00030         json::json_pointer p10("/foo/~");
00031     }
00032     catch (std::domain_error& e)
00033     {
00034         std::cout << "domain_error: " << e.what() << '\n';
00035     }
00036 
00037     // error: JSON pointer uses escape symbol ~ not followed by 0 or 1
00038     try
00039     {
00040         json::json_pointer p11("/foo/~3");
00041     }
00042     catch (std::domain_error& e)
00043     {
00044         std::cout << "domain_error: " << e.what() << '\n';
00045     }
00046 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05