ROOT 6.16/01 Reference Guide |
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.
Public Member Functions | |
json_pointer (const std::string &s="") | |
create JSON pointer More... | |
operator std::string () const | |
return a string representation of the JSON pointer More... | |
std::string | to_string () const noexcept |
return a string representation of the JSON pointer More... | |
Private Member Functions | |
reference | get_and_create (reference j) const |
create and return a reference to the pointed to value More... | |
const_reference | get_checked (const_pointer ptr) const |
reference | get_checked (pointer ptr) const |
const_reference | get_unchecked (const_pointer ptr) const |
return a const reference to the pointed to value More... | |
reference | get_unchecked (pointer ptr) const |
return a reference to the pointed to value More... | |
bool | is_root () const |
return whether pointer points to the root document More... | |
std::string | pop_back () |
remove and return last reference pointer More... | |
json_pointer | top () const |
Static Private Member Functions | |
static std::string | escape (std::string s) |
escape tilde and slash More... | |
static void | flatten (const std::string &reference_string, const basic_json &value, basic_json &result) |
static void | replace_substring (std::string &s, const std::string &f, const std::string &t) |
replace all occurrences of a substring by another string More... | |
static std::vector< std::string > | split (const std::string &reference_string) |
split the string input to reference tokens More... | |
static void | unescape (std::string &s) |
unescape tilde and slash More... | |
static basic_json | unflatten (const basic_json &value) |
Private Attributes | |
std::vector< std::string > | reference_tokens {} |
the reference tokens More... | |
Friends | |
class | basic_json |
allow basic_json to access private members More... | |
bool | operator!= (json_pointer const &lhs, json_pointer const &rhs) noexcept |
bool | operator== (json_pointer const &lhs, json_pointer const &rhs) noexcept |
|
inlineexplicit |
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 |
std::domain_error | if reference token is nonempty and does not begin with a slash (/ ); example: "JSON pointer must be empty or
begin with /" |
std::domain_error | if a tilde (~ ) is not followed by 0 (representing ~ ) or 1 (representing / ); example: "escape error:
~ must be followed with 0 or 1" |
@liveexample{The example shows the construction several valid JSON pointers as well as the exceptional behavior.,json_pointer}
|
inlinestaticprivate |
|
inlinestaticprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
return a reference to the pointed to value
"/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.[in] | ptr | a JSON value |
@complexity Linear in the length of the JSON pointer.
std::out_of_range | if the JSON pointer can not be resolved |
std::domain_error | if an array index begins with '0' |
std::invalid_argument | if an array index was not a number |
|
inlineprivate |
|
inline |
return a string representation of the JSON pointer
ptr
, it holds: @liveexample{The example shows the result of to_string
., json_pointer__to_string}
|
inlineprivate |
|
inlinestaticprivate |
replace all occurrences of a substring by another string
[in,out] | s | the string to manipulate; changed so that all occurrences of f are replaced with t |
[in] | f | the substring to replace with t |
[in] | t | the string to replace f |
|
inlinestaticprivate |
|
inlinenoexcept |
return a string representation of the JSON pointer
ptr
, it holds: @liveexample{The example shows the result of to_string
., json_pointer__to_string}
|
inlineprivate |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
friend |
allow basic_json to access private members
|
friend |
|
friend |
|
private |