Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
nlohmann::json_pointer< BasicJsonType > Class Template Reference

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
 

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 99 of file json.hpp.

Constructor & Destructor Documentation

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

{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 8977 of file json.hpp.

Member Function Documentation

template<typename BasicJsonType >
static int nlohmann::json_pointer< BasicJsonType >::array_index ( const std::string &  s)
inlinestatic
Parameters
[in]sreference token to be converted into an array index
Returns
integer representation of s
Exceptions
out_of_range.404if string s could not be converted to an integer

Definition at line 9019 of file json.hpp.

template<typename BasicJsonType >
static std::string nlohmann::json_pointer< BasicJsonType >::escape ( std::string  s)
inlinestaticprivate

escape "~"" to "~0" and "/" to "~1"

Definition at line 9504 of file json.hpp.

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 9525 of file json.hpp.

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

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 9076 of file json.hpp.

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 9232 of file json.hpp.

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 9356 of file json.hpp.

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

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 9156 of file json.hpp.

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 9297 of file json.hpp.

template<typename BasicJsonType >
bool nlohmann::json_pointer< BasicJsonType >::is_root ( ) const
inlineprivate

return whether pointer points to the root document

Definition at line 9051 of file json.hpp.

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());
Returns
a string representation of the JSON pointer

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

Since
version 2.0.0

Definition at line 9007 of file json.hpp.

template<typename BasicJsonType >
std::string nlohmann::json_pointer< BasicJsonType >::pop_back ( )
inlineprivate

remove and return last reference pointer

Exceptions
out_of_range.405if JSON pointer has no parent

Definition at line 9038 of file json.hpp.

template<typename BasicJsonType >
static void nlohmann::json_pointer< BasicJsonType >::replace_substring ( std::string &  s,
const std::string &  f,
const std::string &  t 
)
inlinestaticprivate

replace all occurrences of a substring by another string

Parameters
[in,out]sthe string to manipulate; changed so that all occurrences of f are replaced with t
[in]fthe substring to replace with t
[in]tthe string to replace f
Precondition
The search string f must not be empty. This precondition is enforced with an assertion.
Since
version 2.0.0

Definition at line 9492 of file json.hpp.

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 9417 of file json.hpp.

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

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

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

Since
version 2.0.0

Definition at line 8996 of file json.hpp.

template<typename BasicJsonType >
json_pointer nlohmann::json_pointer< BasicJsonType >::top ( ) const
inlineprivate

Definition at line 9056 of file json.hpp.

template<typename BasicJsonType >
static void nlohmann::json_pointer< BasicJsonType >::unescape ( std::string &  s)
inlinestaticprivate

unescape "~1" to tilde and "~0" to slash (order is important!)

Definition at line 9512 of file json.hpp.

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 9588 of file json.hpp.

Friends And Related Function Documentation

template<typename BasicJsonType >
friend class basic_json
friend

Definition at line 8953 of file json.hpp.

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

Definition at line 9621 of file json.hpp.

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

Definition at line 9615 of file json.hpp.

Member Data Documentation

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

the reference tokens

Definition at line 9628 of file json.hpp.


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


json_transport
Author(s): Paul Bovbel
autogenerated on Thu Jun 13 2019 19:12:24