JSON for Modern C++ 3.7.3

back
basic_json
empty
json_pointer
operator std::string
operator!=
operator/
operator/
operator/
operator/=
operator/=
operator/=
operator==
parent_pointer
pop_back
push_back
push_back
to_string
| ## ◆ json_pointer() template<typename BasicJsonType >
nlohmann::json_pointer< BasicJsonType >::json_pointer | ( | const std::string & | s = `""` | ) |
| inline explicit
  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. 1 #include <iostream> 2 #include <nlohmann/json.hpp> 3 4 using json = nlohmann::json; 5 6 int 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 } 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 with
      g++ -std=c++11 -Isingle_include doc/examples/json_pointer.cpp -o json_pointer
Since version 2.0.0 Definition at line 11089 of file json.hpp.

nlohmann::basic_json::json_pointer
::nlohmann::json_pointer< basic_json > json_pointer
JSON Pointer, see nlohmann::json_pointer.
Definition: json.hpp:16018
nlohmann::basic_json::parse_error
detail::parse_error parse_error
exception indicating a parse error
Definition: json.hpp:16041
nlohmann::json
basic_json<> json
default JSON class
Definition: json.hpp:2774