nlohmann::json_pointer
json.hpp
typename BasicJsonType
friend class friend class basic_json basic_json
friend json_pointer json_pointer operator/ (const json_pointer &lhs, const json_pointer &rhs) 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

lhs

JSON pointer

rhs

JSON pointer

a new JSON pointer with rhs appended to lhs

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

Linear in the length of lhs and rhs.

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

version 3.6.0

friend json_pointer json_pointer operator/ (const json_pointer &ptr, std::string token) 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

ptr

JSON pointer

token

reference token

a new JSON pointer with unescaped token appended to ptr

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

Linear in the length of ptr.

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

version 3.6.0

friend json_pointer json_pointer operator/ (const json_pointer &ptr, std::size_t array_idx) 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

ptr

JSON pointer

array_idx

array index

a new JSON pointer with array_idx appended to ptr

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

Linear in the length of ptr.

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

version 3.6.0

friend bool bool operator== (json_pointer const &lhs, json_pointer const &rhs) noexcept operator== json_pointer const & lhs json_pointer const & rhs

compares two JSON pointers for equality

lhs

JSON pointer to compare

rhs

JSON pointer to compare

whether lhs is equal to rhs

Linear in the length of the JSON pointer

No-throw guarantee: this function never throws exceptions.

friend bool bool operator!= (json_pointer const &lhs, json_pointer const &rhs) noexcept operator!= json_pointer const & lhs json_pointer const & rhs

compares two JSON pointers for inequality

lhs

JSON pointer to compare

rhs

JSON pointer to compare

whether lhs is not equal rhs

Linear in the length of the JSON pointer

No-throw guarantee: this function never throws exceptions.

JSON_PRIVATE_UNLESS_TESTED JSON_PRIVATE_UNLESS_TESTED nlohmann::json_pointer< BasicJsonType >::__pad0__ __pad0__ json_pointer top() const { if (JSON_HEDLEY_UNLIKELY(empty())) { JSON_THROW(detail::out_of_range::create(405
JSON_PRIVATE_UNLESS_TESTED JSON pointer has no JSON_PRIVATE_UNLESS_TESTED JSON pointer has no nlohmann::json_pointer< BasicJsonType >::parent parent
json_pointer json_pointer nlohmann::json_pointer< BasicJsonType >::result result = *this
result result nlohmann::json_pointer< BasicJsonType >::reference_tokens reference_tokens = {reference_tokens[0]} nlohmann::json_pointer< BasicJsonType >::operator/=
return return nlohmann::json_pointer< BasicJsonType >::result result
std::vector< std::string > std::vector<std::string> nlohmann::json_pointer< BasicJsonType >::reference_tokens reference_tokens

the reference tokens

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

create JSON pointer

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

s

string representing the JSON pointer; if omitted, the empty string is assumed which references the whole JSON value

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

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

version 2.0.0

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

return a string representation of the JSON pointer

For each JSON pointer `ptr`, it holds:

    ptr==json_pointer(ptr.to_string());

a string representation of the JSON pointer

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

version 2.0.0

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

return a string representation of the JSON pointer

For each JSON pointer `ptr`, it holds:

    ptr==json_pointer(ptr.to_string());

a string representation of the JSON pointer

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

version 2.0.0

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

append another JSON pointer at the end of this JSON pointer

ptr

JSON pointer to append

JSON pointer with ptr appended

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

Linear in the length of ptr.

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

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

see operator/(const json_pointer&, const json_pointer&) for a binary operator

version 3.6.0

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

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

token

reference token to append

JSON pointer with token appended without escaping token

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

Amortized constant.

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

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

see operator/(const json_pointer&, std::size_t) for a binary operator

version 3.6.0

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

append an array index at the end of this JSON pointer

array_idx

array index to append

JSON pointer with array_idx appended

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

Amortized constant.

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

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

see operator/(const json_pointer&, std::string) for a binary operator

version 3.6.0

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

returns the parent of this JSON pointer

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

Linear in the length of the JSON pointer.

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

version 3.6.0

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

remove last reference token

not `empty()`

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

Constant.

out_of_range.405

if JSON pointer has no parent

version 3.6.0

nlohmann::detail::out_of_range::create
JSON_HEDLEY_UNLIKELY
JSON_THROW
nlohmann::json_pointer< BasicJsonType >::parent_pointer
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::patch
const std::string & const std::string& nlohmann::json_pointer< BasicJsonType >::back () const back

return last reference token

not `empty()`

last reference token

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

Constant.

out_of_range.405

if JSON pointer has no parent

version 3.6.0

nlohmann::detail::out_of_range::create
JSON_HEDLEY_UNLIKELY
JSON_THROW
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::patch
void void nlohmann::json_pointer< BasicJsonType >::push_back (const std::string &token) push_back const std::string & token

append an unescaped token at the end of the reference pointer

token

token to add

Amortized constant.

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

version 3.6.0

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

append an unescaped token at the end of the reference pointer

token

token to add

Amortized constant.

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

version 3.6.0

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

return whether pointer points to the root document

true iff the JSON pointer points to the root document

Constant.

No-throw guarantee: this function never throws exceptions.

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

version 3.6.0

nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::patch
BasicJsonType::size_type static BasicJsonType::size_type nlohmann::json_pointer< BasicJsonType >::array_index (const std::string &s) array_index const std::string & s

s

reference token to be converted into an array index

integer representation of s

parse_error.106

if an array index begins with '0'

parse_error.109

if an array index begins not with a digit

out_of_range.404

if string s could not be converted to an integer

out_of_range.410

if an array index exceeds size_type

nlohmann::detail::parse_error::create
nlohmann::detail::out_of_range::create
JSON_CATCH
JSON_HEDLEY_UNLIKELY
JSON_PRIVATE_UNLESS_TESTED
JSON_THROW
JSON_TRY
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::patch
std::vector< std::string > static std::vector<std::string> nlohmann::json_pointer< BasicJsonType >::split (const std::string &reference_string) split const std::string & reference_string

split the string input to reference tokens

This function is only called by the json_pointer constructor. All exceptions below are documented there.

parse_error.107

if the pointer is not empty or begins with '/'

parse_error.108

if character '~' is not followed by '0' or '1'

nlohmann::detail::parse_error::create
JSON_ASSERT
JSON_HEDLEY_UNLIKELY
JSON_THROW
nlohmann::detail::unescape
void static void nlohmann::json_pointer< BasicJsonType >::flatten (const std::string &reference_string, const BasicJsonType &value, BasicJsonType &result) flatten const std::string & reference_string const BasicJsonType & value BasicJsonType & result

reference_string

the reference string to the current value

value

the value to consider

result

the result object to insert values to

Empty objects or arrays are flattened to `null`.

nlohmann::detail::array
nlohmann::detail::escape
nlohmann::detail::object
nlohmann::to_string
nlohmann::detail::value
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::flatten
BasicJsonType static BasicJsonType nlohmann::json_pointer< BasicJsonType >::unflatten (const BasicJsonType &value) unflatten const BasicJsonType & value

value

flattened JSON

unflattened JSON

parse_error.109

if array index is not a number

type_error.314

if value is not an object

type_error.315

if object values are not primitive

type_error.313

if value cannot be unflattened

nlohmann::detail::type_error::create
nlohmann::json_pointer< BasicJsonType >::get_and_create
JSON_HEDLEY_UNLIKELY
JSON_THROW
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::unflatten
JSON_PRIVATE_UNLESS_TESTED JSON pointer has no JSON_PRIVATE_UNLESS_TESTED JSON pointer has no nlohmann::json_pointer< BasicJsonType >::BasicJsonType ())) BasicJsonType
BasicJsonType & BasicJsonType& nlohmann::json_pointer< BasicJsonType >::get_and_create (BasicJsonType &j) const get_and_create BasicJsonType & j

create and return a reference to the pointed to value

Linear in the number of reference tokens.

parse_error.109

if array index is not a number

type_error.313

if value cannot be unflattened

nlohmann::detail::array
nlohmann::detail::type_error::create
JSON_THROW
nlohmann::detail::null
nlohmann::detail::object
nlohmann::json_pointer< BasicJsonType >::unflatten
BasicJsonType & BasicJsonType& nlohmann::json_pointer< BasicJsonType >::get_unchecked (BasicJsonType *ptr) const get_unchecked BasicJsonType * ptr

return a reference to the pointed to value

This version does not throw if a value is not present, but tries to create nested values instead. For instance, calling this function with pointer `"/this/that"` on a null value is equivalent to calling `operator[]("this").operator[]("that")` on that value, effectively changing the null value to an object.

ptr

a JSON value

reference to the JSON value pointed to by the JSON pointer

Linear in the length of the JSON pointer.

parse_error.106

if an array index begins with '0'

parse_error.109

if an array index was not a number

out_of_range.404

if the JSON pointer can not be resolved

nlohmann::detail::array
nlohmann::detail::out_of_range::create
JSON_THROW
nlohmann::detail::object
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator[]
BasicJsonType & BasicJsonType& nlohmann::json_pointer< BasicJsonType >::get_checked (BasicJsonType *ptr) const get_checked BasicJsonType * ptr

parse_error.106

if an array index begins with '0'

parse_error.109

if an array index was not a number

out_of_range.402

if the array index '-' is used

out_of_range.404

if the JSON pointer can not be resolved

nlohmann::detail::array
nlohmann::detail::out_of_range::create
JSON_HEDLEY_UNLIKELY
JSON_THROW
nlohmann::detail::object
nlohmann::to_string
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::at
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::value
const BasicJsonType & const BasicJsonType& nlohmann::json_pointer< BasicJsonType >::get_unchecked (const BasicJsonType *ptr) const get_unchecked const BasicJsonType * ptr

return a const reference to the pointed to value

ptr

a JSON value

const reference to the JSON value pointed to by the JSON pointer

parse_error.106

if an array index begins with '0'

parse_error.109

if an array index was not a number

out_of_range.402

if the array index '-' is used

out_of_range.404

if the JSON pointer can not be resolved

nlohmann::detail::array
nlohmann::detail::out_of_range::create
JSON_HEDLEY_UNLIKELY
JSON_THROW
nlohmann::detail::object
nlohmann::to_string
const BasicJsonType & const BasicJsonType& nlohmann::json_pointer< BasicJsonType >::get_checked (const BasicJsonType *ptr) const get_checked const BasicJsonType * ptr

parse_error.106

if an array index begins with '0'

parse_error.109

if an array index was not a number

out_of_range.402

if the array index '-' is used

out_of_range.404

if the JSON pointer can not be resolved

nlohmann::detail::array
nlohmann::detail::out_of_range::create
JSON_HEDLEY_UNLIKELY
JSON_THROW
nlohmann::detail::object
nlohmann::to_string
bool bool nlohmann::json_pointer< BasicJsonType >::contains (const BasicJsonType *ptr) const contains const BasicJsonType * ptr

parse_error.106

if an array index begins with '0'

parse_error.109

if an array index was not a number

nlohmann::detail::array
JSON_HEDLEY_UNLIKELY
nlohmann::detail::object
nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::contains

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.

RFC 6901

version 2.0.0

return
T
JSON_PRIVATE_UNLESS_TESTED
std::vector< T >
+elements
JSON_PRIVATE_UNLESS_TESTED JSON pointer has no
nlohmann::json_pointer< BasicJsonType >
-result
-result
-parent
-__pad0__
-reference_tokens
-reference_tokens
std::basic_string< char >
std::vector< std::string >
+elements
< std::string >
result
std::string
- nlohmann::json_pointer
  __pad0__
- nlohmann::json_pointer
  array_index
- nlohmann::json_pointer
  back
- nlohmann::json_pointer
  basic_json
- nlohmann::json_pointer
  BasicJsonType
- nlohmann::json_pointer
  contains
- nlohmann::json_pointer
  empty
- nlohmann::json_pointer
  flatten
- nlohmann::json_pointer
  get_and_create
- nlohmann::json_pointer
  get_checked
- nlohmann::json_pointer
  get_checked
- nlohmann::json_pointer
  get_unchecked
- nlohmann::json_pointer
  get_unchecked
- nlohmann::json_pointer
  json_pointer
- nlohmann::json_pointer
  operator std::string
- nlohmann::json_pointer
  operator!=
- nlohmann::json_pointer
  operator/
- nlohmann::json_pointer
  operator/
- nlohmann::json_pointer
  operator/
- nlohmann::json_pointer
  operator/=
- nlohmann::json_pointer
  operator/=
- nlohmann::json_pointer
  operator/=
- nlohmann::json_pointer
  operator==
- nlohmann::json_pointer
  parent
- nlohmann::json_pointer
  parent_pointer
- nlohmann::json_pointer
  pop_back
- nlohmann::json_pointer
  push_back
- nlohmann::json_pointer
  push_back
- nlohmann::json_pointer
  reference_tokens
- nlohmann::json_pointer
  reference_tokens
- nlohmann::json_pointer
  result
- nlohmann::json_pointer
  result
- nlohmann::json_pointer
  split
- nlohmann::json_pointer
  to_string
- nlohmann::json_pointer
  unflatten