JSON Pointer. More...
#include <json.hpp>
Public Member Functions | |
const std::string & | back () const |
return last reference token More... | |
bool | empty () const noexcept |
return whether pointer points to the root document More... | |
json_pointer (const std::string &s="") | |
create 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::size_t array_idx) |
append an array index 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 | parent_pointer () const |
returns the parent of this JSON pointer More... | |
void | pop_back () |
remove 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... | |
std::string | to_string () const |
return a string representation of the JSON pointer More... | |
Friends | |
class | basic_json |
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::size_t array_idx) |
create a new JSON pointer by appending the array-index-token at the end of the 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... | |
bool | operator== (json_pointer const &lhs, json_pointer const &rhs) noexcept |
compares two JSON pointers for equality More... | |
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.
|
explicit |
create JSON pointer
Create a JSON pointer according to the syntax described in Section 3 of RFC6901.
[in] | 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 |
@liveexample{The example shows the construction several valid JSON pointers as well as the exceptional behavior.,json_pointer}
const std::string & nlohmann::json_pointer< BasicJsonType >::back | ( | ) | const |
return last reference token
empty()
@liveexample{The example shows the usage of back
.,json_pointer__back}
@complexity Constant.
out_of_range.405 | if JSON pointer has no parent |
References nlohmann::detail::out_of_range::create(), and nlohmann::json_pointer< BasicJsonType >::empty().
|
noexcept |
return whether 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}
Referenced by nlohmann::json_pointer< BasicJsonType >::back(), nlohmann::json_pointer< BasicJsonType >::parent_pointer(), nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::patch(), and nlohmann::json_pointer< BasicJsonType >::pop_back().
nlohmann::json_pointer< BasicJsonType >::operator std::string | ( | ) | const |
return a string representation of the JSON pointer
ptr
, it holds: @liveexample{The example shows the result of to_string
.,json_pointer__to_string}
References nlohmann::json_pointer< BasicJsonType >::to_string().
Referenced by Spreadsheet_legacy.MathParser::hasNext(), and Spreadsheet_legacy.MathParser::peek().
json_pointer & nlohmann::json_pointer< BasicJsonType >::operator/= | ( | const json_pointer< BasicJsonType > & | ptr | ) |
append another JSON pointer at the end of this JSON pointer
[in] | ptr | JSON pointer to append |
@liveexample{The example shows the usage of operator/=
.,json_pointer__operator_add}
@complexity Linear in the length of ptr.
json_pointer & nlohmann::json_pointer< BasicJsonType >::operator/= | ( | std::size_t | array_idx | ) |
append an array index at the end of this JSON pointer
[in] | array_idx | array index to append |
@liveexample{The example shows the usage of operator/=
.,json_pointer__operator_add}
@complexity Amortized constant.
json_pointer & nlohmann::json_pointer< BasicJsonType >::operator/= | ( | std::string | token | ) |
append an unescaped reference token at the end of this JSON pointer
[in] | token | reference token to append |
@liveexample{The example shows the usage of operator/=
.,json_pointer__operator_add}
@complexity Amortized constant.
References draftfunctions.move::move(), and nlohmann::json_pointer< BasicJsonType >::push_back().
json_pointer nlohmann::json_pointer< BasicJsonType >::parent_pointer | ( | ) | const |
returns the parent of this JSON pointer
@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}
References nlohmann::json_pointer< BasicJsonType >::empty(), and nlohmann::json_pointer< BasicJsonType >::pop_back().
void nlohmann::json_pointer< BasicJsonType >::pop_back | ( | ) |
remove last reference token
empty()
@liveexample{The example shows the usage of pop_back
.,json_pointer__pop_back}
@complexity Constant.
out_of_range.405 | if JSON pointer has no parent |
References nlohmann::detail::out_of_range::create(), and nlohmann::json_pointer< BasicJsonType >::empty().
Referenced by nlohmann::json_pointer< BasicJsonType >::parent_pointer(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::patch().
void nlohmann::json_pointer< BasicJsonType >::push_back | ( | const std::string & | token | ) |
append an unescaped token at the end of the reference pointer
[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}
Referenced by nlohmann::json_pointer< BasicJsonType >::operator/=().
void nlohmann::json_pointer< BasicJsonType >::push_back | ( | std::string && | token | ) |
append an unescaped token at the end of the reference pointer
[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}
References draftfunctions.move::move().
std::string nlohmann::json_pointer< BasicJsonType >::to_string | ( | ) | const |
return a string representation of the JSON pointer
ptr
, it holds: @liveexample{The example shows the result of to_string
.,json_pointer__to_string}
Referenced by nlohmann::json_pointer< BasicJsonType >::operator std::string().
|
friend |
|
friend |
compares two JSON pointers for inequality
[in] | lhs | JSON pointer to compare |
[in] | rhs | JSON pointer to compare |
@complexity Linear in the length of the JSON pointer
@exceptionsafety No-throw guarantee: this function never throws exceptions.
|
friend |
create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer
[in] | lhs | JSON pointer |
[in] | rhs | JSON pointer |
@liveexample{The example shows the usage of operator/
.,json_pointer__operator_add_binary}
@complexity Linear in the length of lhs and rhs.
|
friend |
create a new JSON pointer by appending the array-index-token at the end of the JSON pointer
[in] | ptr | JSON pointer |
[in] | array_idx | array index |
@liveexample{The example shows the usage of operator/
.,json_pointer__operator_add_binary}
@complexity Linear in the length of ptr.
|
friend |
create a new JSON pointer by appending the unescaped token at the end of the JSON pointer
[in] | ptr | JSON pointer |
[in] | token | reference token |
@liveexample{The example shows the usage of operator/
.,json_pointer__operator_add_binary}
@complexity Linear in the length of ptr.
|
friend |
compares two JSON pointers for equality
[in] | lhs | JSON pointer to compare |
[in] | rhs | JSON pointer to compare |
@complexity Linear in the length of the JSON pointer
@exceptionsafety No-throw guarantee: this function never throws exceptions.