Create a JSON pointer according to the syntax described in Section 3 of RFC6901.
- Parameters
-
[in] | s | string representing the JSON pointer; if omitted, the empty string is assumed which references the whole JSON value |
- Exceptions
-
parse_error.107 | if the given JSON pointer s is nonempty and does not begin with a slash (/ ); see example below |
parse_error.108 | if a tilde (~ ) in the given JSON pointer s is not followed by 0 (representing ~ ) or 1 (representing / ); see example below |
- Example
- The example shows the construction several valid JSON pointers as well as the exceptional behavior.
2 #include <nlohmann/json.hpp>
25 std::cout << e.what() <<
'\n';
35 std::cout << e.what() <<
'\n';
45 std::cout << e.what() <<
'\n';
Output (play with this example online): [json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'foo'
[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'
[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'
The example code above can be translated withg++ -std=c++11 -Isingle_include doc/examples/json_pointer.cpp -o json_pointer
- Since
- version 2.0.0
Definition at line 10120 of file json.hpp.