Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
nlohmann::json_pointer< BasicJsonType > Class Template Reference

JSON Pointer. More...

#include <json.hpp>

+ Collaboration diagram for nlohmann::json_pointer< BasicJsonType >:

Public Member Functions

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

Private Member Functions

JSON_PRIVATE_UNLESS_TESTED JSON pointer has no BasicJsonType ()))
 
BasicJsonTypeget_and_create (BasicJsonType &j) const
 create and return a reference to the pointed to value
 
BasicJsonTypeget_unchecked (BasicJsonType *ptr) const
 return a reference to the pointed to value
 
BasicJsonTypeget_checked (BasicJsonType *ptr) const
 
const BasicJsonTypeget_unchecked (const BasicJsonType *ptr) const
 return a const reference to the pointed to value
 
const BasicJsonTypeget_checked (const BasicJsonType *ptr) const
 
bool contains (const BasicJsonType *ptr) const
 

Static Private Member Functions

static BasicJsonType::size_type array_index (const std::string &s)
 
static std::vector< std::string > split (const std::string &reference_string)
 split the string input to reference tokens
 
static void flatten (const std::string &reference_string, const BasicJsonType &value, BasicJsonType &result)
 
static BasicJsonType unflatten (const BasicJsonType &value)
 

Private Attributes

JSON_PRIVATE_UNLESS_TESTED : 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 parent
 
json_pointer result = *this
 
result reference_tokens = { reference_tokens[0] }
 
return result
 
std::vector< std::string > reference_tokens
 the reference tokens
 

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
 
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
 
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
 
bool operator== (json_pointer const &lhs, json_pointer const &rhs) noexcept
 compares two JSON pointers for equality
 
bool operator!= (json_pointer const &lhs, json_pointer const &rhs) noexcept
 compares two JSON pointers for inequality
 

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

Definition at line 12379 of file json.hpp.

Constructor & Destructor Documentation

◆ json_pointer()

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]sstring representing the JSON pointer; if omitted, the empty string is assumed which references the whole JSON value
Exceptions
parse_error.107if the given JSON pointer s is nonempty and does not begin with a slash (/); see example below
parse_error.108if 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

Definition at line 12407 of file json.hpp.

Member Function Documentation

◆ array_index()

template<typename BasicJsonType >
static BasicJsonType::size_type nlohmann::json_pointer< BasicJsonType >::array_index ( const std::string & s)
inlinestaticprivate
Parameters
[in]sreference token to be converted into an array index
Returns
integer representation of s
Exceptions
parse_error.106if an array index begins with '0'
parse_error.109if an array index begins not with a digit
out_of_range.404if string s could not be converted to an integer
out_of_range.410if an array index exceeds size_type

Definition at line 12694 of file json.hpp.

◆ back()

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.405if JSON pointer has no parent
Since
version 3.6.0

Definition at line 12631 of file json.hpp.

◆ BasicJsonType()

template<typename BasicJsonType >
JSON_PRIVATE_UNLESS_TESTED JSON pointer has no nlohmann::json_pointer< BasicJsonType >::BasicJsonType ( )
private

◆ contains()

template<typename BasicJsonType >
bool nlohmann::json_pointer< BasicJsonType >::contains ( const BasicJsonType * ptr) const
inlineprivate
Exceptions
parse_error.106if an array index begins with '0'
parse_error.109if an array index was not a number

Definition at line 13058 of file json.hpp.

◆ empty()

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

Definition at line 12678 of file json.hpp.

◆ flatten()

template<typename BasicJsonType >
static void nlohmann::json_pointer< BasicJsonType >::flatten ( const std::string & reference_string,
const BasicJsonType & value,
BasicJsonType & result )
inlinestaticprivate
Parameters
[in]reference_stringthe reference string to the current value
[in]valuethe value to consider
[in,out]resultthe result object to insert values to
Note
Empty objects or arrays are flattened to null.

Definition at line 13214 of file json.hpp.

◆ get_and_create()

template<typename BasicJsonType >
BasicJsonType & nlohmann::json_pointer< BasicJsonType >::get_and_create ( BasicJsonType & j) const
inlineprivate

create and return a reference to the pointed to value

@complexity Linear in the number of reference tokens.

Exceptions
parse_error.109if array index is not a number
type_error.313if value cannot be unflattened

Definition at line 12759 of file json.hpp.

◆ get_checked() [1/2]

template<typename BasicJsonType >
BasicJsonType & nlohmann::json_pointer< BasicJsonType >::get_checked ( BasicJsonType * ptr) const
inlineprivate
Exceptions
parse_error.106if an array index begins with '0'
parse_error.109if an array index was not a number
out_of_range.402if the array index '-' is used
out_of_range.404if the JSON pointer can not be resolved

Definition at line 12905 of file json.hpp.

◆ get_checked() [2/2]

template<typename BasicJsonType >
const BasicJsonType & nlohmann::json_pointer< BasicJsonType >::get_checked ( const BasicJsonType * ptr) const
inlineprivate
Exceptions
parse_error.106if an array index begins with '0'
parse_error.109if an array index was not a number
out_of_range.402if the array index '-' is used
out_of_range.404if the JSON pointer can not be resolved

Definition at line 13010 of file json.hpp.

◆ get_unchecked() [1/2]

template<typename BasicJsonType >
BasicJsonType & nlohmann::json_pointer< BasicJsonType >::get_unchecked ( BasicJsonType * ptr) const
inlineprivate

return a reference to the pointed to value

Note
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.
Parameters
[in]ptra JSON value
Returns
reference to the JSON value pointed to by the JSON pointer

@complexity Linear in the length of the JSON pointer.

Exceptions
parse_error.106if an array index begins with '0'
parse_error.109if an array index was not a number
out_of_range.404if the JSON pointer can not be resolved

Definition at line 12838 of file json.hpp.

◆ get_unchecked() [2/2]

template<typename BasicJsonType >
const BasicJsonType & nlohmann::json_pointer< BasicJsonType >::get_unchecked ( const BasicJsonType * ptr) const
inlineprivate

return a const reference to the pointed to value

Parameters
[in]ptra JSON value
Returns
const reference to the JSON value pointed to by the JSON pointer
Exceptions
parse_error.106if an array index begins with '0'
parse_error.109if an array index was not a number
out_of_range.402if the array index '-' is used
out_of_range.404if the JSON pointer can not be resolved

Definition at line 12962 of file json.hpp.

◆ operator std::string()

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());
json_pointer(const std::string &s="")
create JSON pointer
Definition json.hpp:12407
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

Definition at line 12436 of file json.hpp.

◆ operator/=() [1/3]

append another JSON pointer at the end of this JSON pointer

Parameters
[in]ptrJSON 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
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
Since
version 3.6.0

Definition at line 12457 of file json.hpp.

◆ operator/=() [2/3]

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_idxarray 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
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
Since
version 3.6.0

Definition at line 12503 of file json.hpp.

◆ operator/=() [3/3]

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]tokenreference 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
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
Since
version 3.6.0

Definition at line 12481 of file json.hpp.

◆ parent_pointer()

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

Definition at line 12582 of file json.hpp.

◆ pop_back()

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.405if JSON pointer has no parent
Since
version 3.6.0

Definition at line 12607 of file json.hpp.

◆ push_back() [1/2]

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]tokentoken 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

Definition at line 12653 of file json.hpp.

◆ push_back() [2/2]

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]tokentoken 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

Definition at line 12659 of file json.hpp.

◆ split()

template<typename BasicJsonType >
static std::vector< std::string > nlohmann::json_pointer< BasicJsonType >::split ( const std::string & reference_string)
inlinestaticprivate

split the string input to reference tokens

Note
This function is only called by the json_pointer constructor. All exceptions below are documented there.
Exceptions
parse_error.107if the pointer is not empty or begins with '/'
parse_error.108if character '~' is not followed by '0' or '1'

Definition at line 13146 of file json.hpp.

◆ to_string()

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

Definition at line 12425 of file json.hpp.

◆ unflatten()

template<typename BasicJsonType >
static BasicJsonType nlohmann::json_pointer< BasicJsonType >::unflatten ( const BasicJsonType & value)
inlinestaticprivate
Parameters
[in]valueflattened JSON
Returns
unflattened JSON
Exceptions
parse_error.109if array index is not a number
type_error.314if value is not an object
type_error.315if object values are not primitive
type_error.313if value cannot be unflattened

Definition at line 13285 of file json.hpp.

Friends And Related Symbol Documentation

◆ basic_json

Definition at line 12383 of file json.hpp.

◆ operator!=

template<typename BasicJsonType >
bool operator!= ( json_pointer< BasicJsonType > const & lhs,
json_pointer< BasicJsonType > const & rhs )
friend

compares two JSON pointers for inequality

Parameters
[in]lhsJSON pointer to compare
[in]rhsJSON 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.

Definition at line 13340 of file json.hpp.

◆ operator/ [1/3]

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

Parameters
[in]lhsJSON pointer
[in]rhsJSON 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
see operator/=(const json_pointer&) to append a JSON pointer
Since
version 3.6.0

Definition at line 12523 of file json.hpp.

◆ operator/ [2/3]

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]ptrJSON pointer
[in]array_idxarray 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
see operator/=(std::size_t) to append an array index
Since
version 3.6.0

Definition at line 12564 of file json.hpp.

◆ operator/ [3/3]

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]ptrJSON pointer
[in]tokenreference 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
see operator/=(std::string) to append a reference token
Since
version 3.6.0

Definition at line 12544 of file json.hpp.

◆ operator==

compares two JSON pointers for equality

Parameters
[in]lhsJSON pointer to compare
[in]rhsJSON 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.

Definition at line 13323 of file json.hpp.

Member Data Documentation

◆ __pad0__

Definition at line 12737 of file json.hpp.

◆ parent

Definition at line 12742 of file json.hpp.

◆ reference_tokens [1/2]

template<typename BasicJsonType >
result nlohmann::json_pointer< BasicJsonType >::reference_tokens = { reference_tokens[0] }
private

Definition at line 12746 of file json.hpp.

◆ reference_tokens [2/2]

template<typename BasicJsonType >
std::vector<std::string> nlohmann::json_pointer< BasicJsonType >::reference_tokens
private

the reference tokens

Definition at line 13347 of file json.hpp.

◆ result [1/2]

Definition at line 12745 of file json.hpp.

◆ result [2/2]

Definition at line 12747 of file json.hpp.


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