JSON Pointer. More...
#include <json.hpp>
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... | |
Static Public Member Functions | |
static int | array_index (const std::string &s) |
Private Member Functions | |
BasicJsonType & | get_and_create (BasicJsonType &j) const |
create and return a reference to the pointed to value More... | |
BasicJsonType & | get_checked (BasicJsonType *ptr) const |
const BasicJsonType & | get_checked (const BasicJsonType *ptr) const |
BasicJsonType & | get_unchecked (BasicJsonType *ptr) const |
return a reference to the pointed to value More... | |
const BasicJsonType & | get_unchecked (const BasicJsonType *ptr) const |
return a const 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 "~"" to "~0" and "/" to "~1" More... | |
static void | flatten (const std::string &reference_string, const BasicJsonType &value, BasicJsonType &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 "~1" to tilde and "~0" to slash (order is important!) More... | |
static BasicJsonType | unflatten (const BasicJsonType &value) |
Private Attributes | |
std::vector< std::string > | reference_tokens |
the reference tokens More... | |
Friends | |
class | basic_json |
bool | operator!= (json_pointer const &lhs, json_pointer const &rhs) noexcept |
bool | operator== (json_pointer const &lhs, json_pointer const &rhs) noexcept |
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.
|
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 |
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}
|
inlinestatic |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
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 |
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 |
|
inlineprivate |
return a const reference to the pointed to value
[in] | ptr | a JSON value |
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 |
|
inlineprivate |
|
inline |
return a string representation of the JSON pointer
ptr
, it holds: {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 |
split the string input to reference tokens
parse_error.107 | if the pointer is not empty or begins with '/' |
parse_error.108 | if character '~' is not followed by '0' or '1' |
|
inlinenoexcept |
return a string representation of the JSON pointer
ptr
, it holds: {The example shows the result of to_string
., json_pointer__to_string}
|
inlineprivate |
|
inlinestaticprivate |
|
inlinestaticprivate |
|
friend |
|
friend |
|
friend |
|
private |