nlohmann::json_pointer< BasicJsonType > Class Template Reference

JSON Pointer. More...

`#include <json.hpp>`

## Public Member Functions

| json_pointer (const std::string &s="")
| create JSON pointer More...
std::string | to_string () const
| return a string representation of the JSON pointer More...
| operator std::string () const
| return a string representation of the JSON pointer More...
json_pointer & | operator/= (const json_pointer &ptr)
| append another JSON pointer at the end of this JSON pointer More...
json_pointer & | operator/= (std::string token)
| append an unescaped reference token at the end of this JSON pointer More...
json_pointer & | operator/= (std::size_t array_index)
| append an array index at the end of this JSON pointer More...
json_pointer | parent_pointer () const
| returns the parent of this JSON pointer More...
void | pop_back ()
| remove last reference token More...
const std::string & | back () const
| return last reference token More...
void | push_back (const std::string &token)
| append an unescaped token at the end of the reference pointer More...
void | push_back (std::string &&token)
| append an unescaped token at the end of the reference pointer More...
bool | empty () const noexcept
| return whether pointer points to the root document More...
| json_pointer (const std::string &s="")
| create JSON pointer More...
std::string | to_string () const
| return a string representation of the JSON pointer More...
| operator std::string () const
| return a string representation of the JSON pointer More...
json_pointer & | operator/= (const json_pointer &ptr)
| append another JSON pointer at the end of this JSON pointer More...
json_pointer & | operator/= (std::string token)
| append an unescaped reference token at the end of this JSON pointer More...
json_pointer & | operator/= (std::size_t array_idx)
| append an array index at the end of this JSON pointer More...
json_pointer | parent_pointer () const
| returns the parent of this JSON pointer More...
void | pop_back ()
| remove last reference token More...
const std::string & | back () const
| return last reference token More...
void | push_back (const std::string &token)
| append an unescaped token at the end of the reference pointer More...
void | push_back (std::string &&token)
| append an unescaped token at the end of the reference pointer More...
bool | empty () const noexcept
| return whether pointer points to the root document More...

## Friends

class | basic_json
json_pointer | operator/ (const json_pointer &lhs, const json_pointer &rhs)
| create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer More...
json_pointer | operator/ (const json_pointer &ptr, std::string token)
| create a new JSON pointer by appending the unescaped token at the end of the JSON pointer More...
json_pointer | operator/ (const json_pointer &ptr, std::size_t array_index)
| create a new JSON pointer by appending the array-index-token at the end of the JSON pointer More...
bool | operator== (json_pointer const &lhs, json_pointer const &rhs) noexcept
| compares two JSON pointers for equality More...
bool | operator!= (json_pointer const &lhs, json_pointer const &rhs) noexcept
| compares two JSON pointers for inequality More...
json_pointer | operator/ (const json_pointer &lhs, const json_pointer &rhs)
| create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer More...
json_pointer | operator/ (const json_pointer &ptr, std::string token)
| create a new JSON pointer by appending the unescaped token at the end of the JSON pointer More...
json_pointer | operator/ (const json_pointer &ptr, std::size_t array_idx)
| create a new JSON pointer by appending the array-index-token at the end of the JSON pointer More...
bool | operator== (json_pointer const &lhs, json_pointer const &rhs) noexcept
| compares two JSON pointers for equality More...
bool | operator!= (json_pointer const &lhs, json_pointer const &rhs) noexcept
| compares two JSON pointers for inequality More...

## Detailed Description

### template<typename BasicJsonType>
class nlohmann::json_pointer< BasicJsonType >

JSON Pointer.

A JSON pointer defines a string syntax for identifying a specific value within a JSON document. It can be used with functions `at` and `operator[]`. Furthermore, JSON pointers are the base for JSON patches.

See also
  RFC 6901

Since
  version 2.0.0

## Constructor & Destructor Documentation

## json_pointer() [1/2]

template<typename BasicJsonType >

nlohmann::json_pointer< BasicJsonType >::json_pointer | ( | const std::string & | s = `""` | ) |

inlineexplicit

create JSON pointer

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

@liveexample{The example shows the construction several valid JSON pointers as well as the exceptional behavior.,json_pointer}

Since
  version 2.0.0

## json_pointer() [2/2]

template<typename BasicJsonType >

nlohmann::json_pointer< BasicJsonType >::json_pointer | ( | const std::string & | s = `""` | ) |

inlineexplicit

create JSON pointer

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

@liveexample{The example shows the construction several valid JSON pointers as well as the exceptional behavior.,json_pointer}

Since
  version 2.0.0

## Member Function Documentation

## back() [1/2]

template<typename BasicJsonType >

const std::string& nlohmann::json_pointer< BasicJsonType >::back | ( |  | ) | const

inline

return last reference token

Precondition
  not `empty()`

Returns
  last reference token

@liveexample{The example shows the usage of `back`.,json_pointer__back}

@complexity Constant.

Exceptions

  out_of_range.405 | if JSON pointer has no parent

Since
  version 3.6.0

## back() [2/2]

template<typename BasicJsonType >

const std::string& nlohmann::json_pointer< BasicJsonType >::back | ( |  | ) | const

inline

return last reference token

Precondition
  not `empty()`

Returns
  last reference token

@liveexample{The example shows the usage of `back`.,json_pointer__back}

@complexity Constant.

Exceptions

  out_of_range.405 | if JSON pointer has no parent

Since
  version 3.6.0

## empty() [1/2]

template<typename BasicJsonType >

bool nlohmann::json_pointer< BasicJsonType >::empty | ( |  | ) | const

inlinenoexcept

return whether pointer points to the root document

Returns
  true iff the JSON pointer points to the root document

@complexity Constant.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example shows the result of `empty` for different JSON Pointers.,json_pointer__empty}

Since
  version 3.6.0

## empty() [2/2]

template<typename BasicJsonType >

bool nlohmann::json_pointer< BasicJsonType >::empty | ( |  | ) | const

inlinenoexcept

return whether pointer points to the root document

Returns
  true iff the JSON pointer points to the root document

@complexity Constant.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example shows the result of `empty` for different JSON Pointers.,json_pointer__empty}

Since
  version 3.6.0

## operator std::string() [1/2]

template<typename BasicJsonType >

nlohmann::json_pointer< BasicJsonType >::operator std::string | ( |  | ) | const

inline

return a string representation of the JSON pointer

Invariant
  For each JSON pointer `ptr`, it holds:
  ptr == json_pointer(ptr.to_string());

Returns
  a string representation of the JSON pointer

@liveexample{The example shows the result of `to_string`.,json_pointer__to_string}

Since
  version 2.0.0

## operator std::string() [2/2]

template<typename BasicJsonType >

nlohmann::json_pointer< BasicJsonType >::operator std::string | ( |  | ) | const

inline

return a string representation of the JSON pointer

Invariant
  For each JSON pointer `ptr`, it holds:
  ptr == json_pointer(ptr.to_string());

Returns
  a string representation of the JSON pointer

@liveexample{The example shows the result of `to_string`.,json_pointer__to_string}

Since
  version 2.0.0

## operator/=() [1/6]

template<typename BasicJsonType >

json_pointer& nlohmann::json_pointer< BasicJsonType >::operator/= | ( | const json_pointer< BasicJsonType > & | ptr | ) |

inline

append another JSON pointer at the end of this JSON pointer

Parameters

  [in] | ptr | JSON pointer to append

Returns
  JSON pointer with ptr appended

@liveexample{The example shows the usage of `operator/=`.,json_pointer__operator_add}

@complexity Linear in the length of ptr.

See also
  operator/=(std::string) to append a reference token
  operator/=(std::size_t) to append an array index
  operator/(const json_pointer&, const json_pointer&) for a binary operator

Since
  version 3.6.0

## operator/=() [2/6]

template<typename BasicJsonType >

json_pointer& nlohmann::json_pointer< BasicJsonType >::operator/= | ( | const json_pointer< BasicJsonType > & | ptr | ) |

inline

append another JSON pointer at the end of this JSON pointer

Parameters

  [in] | ptr | JSON pointer to append

Returns
  JSON pointer with ptr appended

@liveexample{The example shows the usage of `operator/=`.,json_pointer__operator_add}

@complexity Linear in the length of ptr.

See also
  operator/=(std::string) to append a reference token
  operator/=(std::size_t) to append an array index
  operator/(const json_pointer&, const json_pointer&) for a binary operator

Since
  version 3.6.0

## operator/=() [3/6]

template<typename BasicJsonType >

json_pointer& nlohmann::json_pointer< BasicJsonType >::operator/= | ( | std::size_t | array_idx | ) |

inline

append an array index at the end of this JSON pointer

Parameters

  [in] | array_idx | array index to append

Returns
  JSON pointer with array_idx appended

@liveexample{The example shows the usage of `operator/=`.,json_pointer__operator_add}

@complexity Amortized constant.

See also
  operator/=(const json_pointer&) to append a JSON pointer
  operator/=(std::string) to append a reference token
  operator/(const json_pointer&, std::string) for a binary operator

Since
  version 3.6.0

## operator/=() [4/6]

template<typename BasicJsonType >

json_pointer& nlohmann::json_pointer< BasicJsonType >::operator/= | ( | std::size_t | array_index | ) |

inline

append an array index at the end of this JSON pointer

Parameters

  [in] | array_index | array index to append

Returns
  JSON pointer with array_index appended

@liveexample{The example shows the usage of `operator/=`.,json_pointer__operator_add}

@complexity Amortized constant.

See also
  operator/=(const json_pointer&) to append a JSON pointer
  operator/=(std::string) to append a reference token
  operator/(const json_pointer&, std::string) for a binary operator

Since
  version 3.6.0

## operator/=() [5/6]

template<typename BasicJsonType >

json_pointer& nlohmann::json_pointer< BasicJsonType >::operator/= | ( | std::string | token | ) |

inline

append an unescaped reference token at the end of this JSON pointer

Parameters

  [in] | token | reference token to append

Returns
  JSON pointer with token appended without escaping token

@liveexample{The example shows the usage of `operator/=`.,json_pointer__operator_add}

@complexity Amortized constant.

See also
  operator/=(const json_pointer&) to append a JSON pointer
  operator/=(std::size_t) to append an array index
  operator/(const json_pointer&, std::size_t) for a binary operator

Since
  version 3.6.0

## operator/=() [6/6]

template<typename BasicJsonType >

json_pointer& nlohmann::json_pointer< BasicJsonType >::operator/= | ( | std::string | token | ) |

inline

append an unescaped reference token at the end of this JSON pointer

Parameters

  [in] | token | reference token to append

Returns
  JSON pointer with token appended without escaping token

@liveexample{The example shows the usage of `operator/=`.,json_pointer__operator_add}

@complexity Amortized constant.

See also
  operator/=(const json_pointer&) to append a JSON pointer
  operator/=(std::size_t) to append an array index
  operator/(const json_pointer&, std::size_t) for a binary operator

Since
  version 3.6.0

## parent_pointer() [1/2]

template<typename BasicJsonType >

json_pointer nlohmann::json_pointer< BasicJsonType >::parent_pointer | ( |  | ) | const

inline

returns the parent of this JSON pointer

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.

@liveexample{The example shows the result of `parent_pointer` for different JSON Pointers.,json_pointer__parent_pointer}

Since
  version 3.6.0

## parent_pointer() [2/2]

template<typename BasicJsonType >

json_pointer nlohmann::json_pointer< BasicJsonType >::parent_pointer | ( |  | ) | const

inline

returns the parent of this JSON pointer

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.

@liveexample{The example shows the result of `parent_pointer` for different JSON Pointers.,json_pointer__parent_pointer}

Since
  version 3.6.0

## pop_back() [1/2]

template<typename BasicJsonType >

void nlohmann::json_pointer< BasicJsonType >::pop_back | ( |  | ) |

inline

remove last reference token

Precondition
  not `empty()`

@liveexample{The example shows the usage of `pop_back`.,json_pointer__pop_back}

@complexity Constant.

Exceptions

  out_of_range.405 | if JSON pointer has no parent

Since
  version 3.6.0

## pop_back() [2/2]

template<typename BasicJsonType >

void nlohmann::json_pointer< BasicJsonType >::pop_back | ( |  | ) |

inline

remove last reference token

Precondition
  not `empty()`

@liveexample{The example shows the usage of `pop_back`.,json_pointer__pop_back}

@complexity Constant.

Exceptions

  out_of_range.405 | if JSON pointer has no parent

Since
  version 3.6.0

## push_back() [1/4]

template<typename BasicJsonType >

void nlohmann::json_pointer< BasicJsonType >::push_back | ( | const std::string & | token | ) |

inline

append an unescaped token at the end of the reference pointer

Parameters

  [in] | token | token to add

@complexity Amortized constant.

@liveexample{The example shows the result of `push_back` for different JSON Pointers.,json_pointer__push_back}

Since
  version 3.6.0

## push_back() [2/4]

template<typename BasicJsonType >

void nlohmann::json_pointer< BasicJsonType >::push_back | ( | const std::string & | token | ) |

inline

append an unescaped token at the end of the reference pointer

Parameters

  [in] | token | token to add

@complexity Amortized constant.

@liveexample{The example shows the result of `push_back` for different JSON Pointers.,json_pointer__push_back}

Since
  version 3.6.0

## push_back() [3/4]

template<typename BasicJsonType >

void nlohmann::json_pointer< BasicJsonType >::push_back | ( | std::string && | token | ) |

inline

append an unescaped token at the end of the reference pointer

Parameters

  [in] | token | token to add

@complexity Amortized constant.

@liveexample{The example shows the result of `push_back` for different JSON Pointers.,json_pointer__push_back}

Since
  version 3.6.0

## push_back() [4/4]

template<typename BasicJsonType >

void nlohmann::json_pointer< BasicJsonType >::push_back | ( | std::string && | token | ) |

inline

append an unescaped token at the end of the reference pointer

Parameters

  [in] | token | token to add

@complexity Amortized constant.

@liveexample{The example shows the result of `push_back` for different JSON Pointers.,json_pointer__push_back}

Since
  version 3.6.0

## to_string() [1/2]

template<typename BasicJsonType >

std::string nlohmann::json_pointer< BasicJsonType >::to_string | ( |  | ) | const

inline

return a string representation of the JSON pointer

Invariant
  For each JSON pointer `ptr`, it holds:
  ptr == json_pointer(ptr.to_string());

Returns
  a string representation of the JSON pointer

@liveexample{The example shows the result of `to_string`.,json_pointer__to_string}

Since
  version 2.0.0

## to_string() [2/2]

template<typename BasicJsonType >

std::string nlohmann::json_pointer< BasicJsonType >::to_string | ( |  | ) | const

inline

return a string representation of the JSON pointer

Invariant
  For each JSON pointer `ptr`, it holds:
  ptr == json_pointer(ptr.to_string());

Returns
  a string representation of the JSON pointer

@liveexample{The example shows the result of `to_string`.,json_pointer__to_string}

Since
  version 2.0.0

## Friends And Related Function Documentation

## basic_json

template<typename BasicJsonType >

basic_json

friend

## operator!= [1/2]

template<typename BasicJsonType >

bool operator!= | ( | json_pointer< BasicJsonType > const & | lhs,
|  | json_pointer< BasicJsonType > const & | rhs
| ) |  |

friend

compares two JSON pointers for inequality

Parameters

  [in] | lhs | JSON pointer to compare
  [in] | rhs | JSON pointer to compare

Returns
  whether lhs is not equal rhs

@complexity Linear in the length of the JSON pointer

@exceptionsafety No-throw guarantee: this function never throws exceptions.

## operator!= [2/2]

template<typename BasicJsonType >

bool operator!= | ( | json_pointer< BasicJsonType > const & | lhs,
|  | json_pointer< BasicJsonType > const & | rhs
| ) |  |

friend

compares two JSON pointers for inequality

Parameters

  [in] | lhs | JSON pointer to compare
  [in] | rhs | JSON pointer to compare

Returns
  whether lhs is not equal rhs

@complexity Linear in the length of the JSON pointer

@exceptionsafety No-throw guarantee: this function never throws exceptions.

## operator/ [1/6]

template<typename BasicJsonType >

json_pointer operator/ | ( | const json_pointer< BasicJsonType > & | lhs,
|  | const json_pointer< BasicJsonType > & | rhs
| ) |  |

friend

create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer

Parameters

  [in] | lhs | JSON pointer
  [in] | rhs | JSON pointer

Returns
  a new JSON pointer with rhs appended to lhs

@liveexample{The example shows the usage of `operator/`.,json_pointer__operator_add_binary}

@complexity Linear in the length of lhs and rhs.

See also
  operator/=(const json_pointer&) to append a JSON pointer

Since
  version 3.6.0

## operator/ [2/6]

template<typename BasicJsonType >

json_pointer operator/ | ( | const json_pointer< BasicJsonType > & | lhs,
|  | const json_pointer< BasicJsonType > & | rhs
| ) |  |

friend

create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer

Parameters

  [in] | lhs | JSON pointer
  [in] | rhs | JSON pointer

Returns
  a new JSON pointer with rhs appended to lhs

@liveexample{The example shows the usage of `operator/`.,json_pointer__operator_add_binary}

@complexity Linear in the length of lhs and rhs.

See also
  operator/=(const json_pointer&) to append a JSON pointer

Since
  version 3.6.0

## operator/ [3/6]

template<typename BasicJsonType >

json_pointer operator/ | ( | const json_pointer< BasicJsonType > & | ptr,
|  | std::size_t | array_idx
| ) |  |

friend

create a new JSON pointer by appending the array-index-token at the end of the JSON pointer

Parameters

  [in] | ptr | JSON pointer
  [in] | array_idx | array index

Returns
  a new JSON pointer with array_idx appended to ptr

@liveexample{The example shows the usage of `operator/`.,json_pointer__operator_add_binary}

@complexity Linear in the length of ptr.

See also
  operator/=(std::size_t) to append an array index

Since
  version 3.6.0

## operator/ [4/6]

template<typename BasicJsonType >

json_pointer operator/ | ( | const json_pointer< BasicJsonType > & | ptr,
|  | std::size_t | array_index
| ) |  |

friend

create a new JSON pointer by appending the array-index-token at the end of the JSON pointer

Parameters

  [in] | ptr | JSON pointer
  [in] | array_index | array index

Returns
  a new JSON pointer with array_index appended to ptr

@liveexample{The example shows the usage of `operator/`.,json_pointer__operator_add_binary}

@complexity Linear in the length of ptr.

See also
  operator/=(std::size_t) to append an array index

Since
  version 3.6.0

## operator/ [5/6]

template<typename BasicJsonType >

json_pointer operator/ | ( | const json_pointer< BasicJsonType > & | ptr,
|  | std::string | token
| ) |  |

friend

create a new JSON pointer by appending the unescaped token at the end of the JSON pointer

Parameters

  [in] | ptr | JSON pointer
  [in] | token | reference token

Returns
  a new JSON pointer with unescaped token appended to ptr

@liveexample{The example shows the usage of `operator/`.,json_pointer__operator_add_binary}

@complexity Linear in the length of ptr.

See also
  operator/=(std::string) to append a reference token

Since
  version 3.6.0

## operator/ [6/6]

template<typename BasicJsonType >

json_pointer operator/ | ( | const json_pointer< BasicJsonType > & | ptr,
|  | std::string | token
| ) |  |

friend

create a new JSON pointer by appending the unescaped token at the end of the JSON pointer

Parameters

  [in] | ptr | JSON pointer
  [in] | token | reference token

Returns
  a new JSON pointer with unescaped token appended to ptr

@liveexample{The example shows the usage of `operator/`.,json_pointer__operator_add_binary}

@complexity Linear in the length of ptr.

See also
  operator/=(std::string) to append a reference token

Since
  version 3.6.0

## operator== [1/2]

template<typename BasicJsonType >

bool operator== | ( | json_pointer< BasicJsonType > const & | lhs,
|  | json_pointer< BasicJsonType > const & | rhs
| ) |  |

friend

compares two JSON pointers for equality

Parameters

  [in] | lhs | JSON pointer to compare
  [in] | rhs | JSON pointer to compare

Returns
  whether lhs is equal to rhs

@complexity Linear in the length of the JSON pointer

@exceptionsafety No-throw guarantee: this function never throws exceptions.

## operator== [2/2]

template<typename BasicJsonType >

bool operator== | ( | json_pointer< BasicJsonType > const & | lhs,
|  | json_pointer< BasicJsonType > const & | rhs
| ) |  |

friend

compares two JSON pointers for equality

Parameters

  [in] | lhs | JSON pointer to compare
  [in] | rhs | JSON pointer to compare

Returns
  whether lhs is equal to rhs

@complexity Linear in the length of the JSON pointer

@exceptionsafety No-throw guarantee: this function never throws exceptions.

The documentation for this class was generated from the following file:

- build/_deps/json-src/include/nlohmann/json.hpp

nlohmann::json_pointer::json_pointer
json_pointer(const std::string &s="")
create JSON pointer
Definition: json.hpp:10120