Skip to content

nlohmann::json_pointer::parent_pointer

json_pointerparent_pointer()const;

Returns the parent of this JSON pointer.

Return value

Parent of this JSON pointer; in case this JSON pointer is the root, the root itself is returned.

Exception safety

No-throw guarantee: this function never throws exceptions.

Complexity

Linear in the length of the JSON pointer.

Examples

Example

The example shows the result of parent_pointer for different JSON Pointers.

#include<iostream>
#include<nlohmann/json.hpp>
usingjson=nlohmann::json;
intmain()
{
// different JSON Pointers
json::json_pointerptr1("");
json::json_pointerptr2("/foo");
json::json_pointerptr3("/foo/0");
// call parent_pointer()
std::cout<<std::boolalpha
<<"parent of \""<<ptr1<<"\" is \""<<ptr1.parent_pointer()<<"\"\n"
<<"parent of \""<<ptr2<<"\" is \""<<ptr2.parent_pointer()<<"\"\n"
<<"parent of \""<<ptr3<<"\" is \""<<ptr3.parent_pointer()<<"\""<<std::endl;
}

Output:

parentof""is""
parentof"/foo"is""
parentof"/foo/0"is"/foo"

See also

  • pop_back remove the last reference token
  • back return the last reference token

Version history

Added in version 3.6.0.

AltStyle によって変換されたページ (->オリジナル) /