JSON for Modern C++  2.0.0
template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
nlohmann::basic_json::json_pointer::json_pointer ( const std::string &  s = "")
inlineexplicit

Create a JSON pointer according to the syntax described in Section 3 of RFC6901.

Parameters
[in]sstring representing the JSON pointer; if omitted, the empty string is assumed which references the whole JSON value
Exceptions
std::domain_errorif reference token is nonempty and does not begin with a slash (/); example: "JSON pointer must be empty or begin with /"
std::domain_errorif a tilde (~) is not followed by 0 (representing ~) or 1 (representing /); example: "escape error: ~ must be followed with 0 or 1"
Example
The example shows the construction several valid JSON pointers as well as the exceptional behavior.
1 #include <json.hpp>
2 
3 using json = nlohmann::json;
4 
5 int main()
6 {
7  // correct JSON pointers
8  json::json_pointer p1;
9  json::json_pointer p2("");
10  json::json_pointer p3("/");
11  json::json_pointer p4("//");
12  json::json_pointer p5("/foo/bar");
13  json::json_pointer p6("/foo/bar/-");
14  json::json_pointer p7("/foo/~0");
15  json::json_pointer p8("/foo/~1");
16 
17  // error: JSON pointer does not begin with a slash
18  try
19  {
20  json::json_pointer p9("foo");
21  }
22  catch (std::domain_error& e)
23  {
24  std::cout << "domain_error: " << e.what() << '\n';
25  }
26 
27  // error: JSON pointer uses escape symbol ~ not followed by 0 or 1
28  try
29  {
30  json::json_pointer p10("/foo/~");
31  }
32  catch (std::domain_error& e)
33  {
34  std::cout << "domain_error: " << e.what() << '\n';
35  }
36 
37  // error: JSON pointer uses escape symbol ~ not followed by 0 or 1
38  try
39  {
40  json::json_pointer p11("/foo/~3");
41  }
42  catch (std::domain_error& e)
43  {
44  std::cout << "domain_error: " << e.what() << '\n';
45  }
46 }
basic_json<> json
default JSON class
Definition: json.hpp:9587
Output (play with this example online):
domain_error: JSON pointer must be empty or begin with '/'
domain_error: escape error: '~' must be followed with '0' or '1'
domain_error: escape error: '~' must be followed with '0' or '1'
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/json_pointer.cpp -o json_pointer 
Since
version 2.0.0

Definition at line 8383 of file json.hpp.