JSON for Modern C++  3.7.0

◆ parent_pointer()

template<typename BasicJsonType >
json_pointer nlohmann::json_pointer< BasicJsonType >::parent_pointer ( ) const
inline
Returns
parent of this JSON pointer; in case this JSON pointer is the root, the root itself is returned
Complexity
Linear in the length of the JSON pointer.
Example
The example shows the result of parent_pointer for different JSON Pointers.
1 #include <iostream>
2 #include <nlohmann/json.hpp>
3 
4 using json = nlohmann::json;
5 
6 int main()
7 {
8  // different JSON Pointers
9  json::json_pointer ptr1("");
10  json::json_pointer ptr2("/foo");
11  json::json_pointer ptr3("/foo/0");
12 
13  // call parent_pointer()
14  std::cout << std::boolalpha
15  << "parent of " << ptr1 << " is " << ptr1.parent_pointer() << '\n'
16  << "parent of " << ptr2 << " is " << ptr2.parent_pointer() << '\n'
17  << "parent of " << ptr3 << " is " << ptr3.parent_pointer() << std::endl;
18 }
basic_json<> json
default JSON class
Definition: json.hpp:2355
::nlohmann::json_pointer< basic_json > json_pointer
JSON Pointer, see nlohmann::json_pointer.
Definition: json.hpp:14616

Output (play with this example online):
parent of "" is ""
parent of "/foo" is ""
parent of "/foo/0" is "/foo"
The example code above can be translated with
g++ -std=c++11 -Isingle_include doc/examples/json_pointer__parent_pointer.cpp -o json_pointer__parent_pointer 
Since
version 3.6.0

Definition at line 10183 of file json.hpp.