JSON for Modern C++  3.7.0

◆ back()

template<typename BasicJsonType >
const std::string& nlohmann::json_pointer< BasicJsonType >::back ( )
inline
Precondition
not empty()
Returns
last reference token
Example
The example shows the usage of back.
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("/foo");
10  json::json_pointer ptr2("/foo/0");
11 
12  // call empty()
13  std::cout << "last reference token of " << ptr1 << " is " << ptr1.back() << '\n'
14  << "last reference token of " << ptr2 << " is " << ptr2.back() << std::endl;
15 }
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):
last reference token of "/foo" is foo
last reference token of "/foo/0" is 0
The example code above can be translated with
g++ -std=c++11 -Isingle_include doc/examples/json_pointer__back.cpp -o json_pointer__back 
Complexity
Constant.
Exceptions
out_of_range.405if JSON pointer has no parent
Since
version 3.6.0

Definition at line 10232 of file json.hpp.