|
| std::string | pop_back () |
| | remove and return last reference pointer More...
|
| |
| bool | is_root () const noexcept |
| | return whether pointer points to the root document More...
|
| |
| json_pointer | top () const |
| |
| BasicJsonType & | get_and_create (BasicJsonType &j) const |
| | create and return a reference to the pointed to value More...
|
| |
| BasicJsonType & | get_unchecked (BasicJsonType *ptr) const |
| | return a reference to the pointed to value More...
|
| |
| BasicJsonType & | get_checked (BasicJsonType *ptr) const |
| |
| const BasicJsonType & | get_unchecked (const BasicJsonType *ptr) const |
| | return a const reference to the pointed to value More...
|
| |
| const BasicJsonType & | get_checked (const BasicJsonType *ptr) const |
| |
|
| static std::vector< std::string > | split (const std::string &reference_string) |
| | split the string input to reference tokens More...
|
| |
| 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::string | escape (std::string s) |
| | escape "~" to "~0" and "/" to "~1" More...
|
| |
| static void | unescape (std::string &s) |
| | unescape "~1" to tilde and "~0" to slash (order is important!) More...
|
| |
| static void | flatten (const std::string &reference_string, const BasicJsonType &value, BasicJsonType &result) |
| |
| static BasicJsonType | unflatten (const BasicJsonType &value) |
| |
|
| template<template< typename, typename, typename... > class ObjectType, template< typename, typename... > class ArrayType, class StringType , class BooleanType , class NumberIntegerType , class NumberUnsignedType , class NumberFloatType , template< typename > class AllocatorType, template< typename, typename=void > class JSONSerializer> |
| 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 |
| |
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 100 of file json.hpp.
template<typename BasicJsonType >
- Parameters
-
| [in] | s | reference token to be converted into an array index |
- Returns
- integer representation of s
- Exceptions
-
| out_of_range.404 | if string s could not be converted to an integer |
Definition at line 11665 of file json.hpp.
References nlohmann::detail::out_of_range::create(), JSON_THROW, and JSON_UNLIKELY.
Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::patch().
11667 std::size_t processed_chars = 0;
11668 const int res = std::stoi(s, &processed_chars);
#define JSON_THROW(exception)
static out_of_range create(int id_, const std::string &what_arg)
template<typename BasicJsonType >
| static void nlohmann::json_pointer< BasicJsonType >::flatten |
( |
const std::string & |
reference_string, |
|
|
const BasicJsonType & |
value, |
|
|
BasicJsonType & |
result |
|
) |
| |
|
inlinestaticprivate |
- Parameters
-
| [in] | reference_string | the reference string to the current value |
| [in] | value | the value to consider |
| [in,out] | result | the result object to insert values to |
- Note
- Empty objects or arrays are flattened to
null.
Definition at line 12171 of file json.hpp.
References nlohmann::detail::array, nlohmann::detail::object, and Catch::Generators::value().
Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::flatten().
12175 switch (
value.m_type)
12179 if (
value.m_value.array->empty())
12182 result[reference_string] =
nullptr;
12187 for (std::size_t i = 0; i <
value.m_value.array->size(); ++i)
12189 flatten(reference_string +
"/" + std::to_string(i),
12190 value.m_value.array->operator[](i), result);
12198 if (
value.m_value.object->empty())
12201 result[reference_string] =
nullptr;
12206 for (
const auto& element : *
value.m_value.object)
12208 flatten(reference_string +
"/" +
escape(element.first), element.second, result);
12217 result[reference_string] =
value;
array (ordered collection of values)
static std::string escape(std::string s)
escape "~" to "~0" and "/" to "~1"
object (unordered set of name/value pairs)
static void flatten(const std::string &reference_string, const BasicJsonType &value, BasicJsonType &result)
auto value(T const &val) -> Generator< T >
template<typename BasicJsonType >
create and return a reference to the pointed to value
Linear in the number of reference tokens.
- Exceptions
-
| parse_error.109 | if array index is not a number |
| type_error.313 | if value cannot be unflattened |
Definition at line 11722 of file json.hpp.
References nlohmann::detail::array, nlohmann::detail::parse_error::create(), nlohmann::detail::type_error::create(), JSON_CATCH, JSON_THROW, JSON_TRY, nlohmann::detail::null, and nlohmann::detail::object.
Referenced by nlohmann::json_pointer< BasicJsonType >::unflatten().
11724 using size_type =
typename BasicJsonType::size_type;
11731 switch (result->m_type)
11735 if (reference_token ==
"0")
11738 result = &result->operator[](0);
11743 result = &result->operator[](reference_token);
11751 result = &result->operator[](reference_token);
11760 result = &result->operator[](
static_cast<size_type
>(
array_index(reference_token)));
#define JSON_CATCH(exception)
array (ordered collection of values)
#define JSON_THROW(exception)
object (unordered set of name/value pairs)
static int array_index(const std::string &s)
std::vector< std::string > reference_tokens
the reference tokens
static type_error create(int id_, const std::string &what_arg)
static parse_error create(int id_, const position_t &pos, const std::string &what_arg)
create a parse error exception
template<typename BasicJsonType >
- Exceptions
-
| 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 |
Definition at line 11878 of file json.hpp.
References nlohmann::detail::array, nlohmann::detail::parse_error::create(), nlohmann::detail::out_of_range::create(), JSON_CATCH, JSON_THROW, JSON_TRY, JSON_UNLIKELY, and nlohmann::detail::object.
Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::at(), and nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::value().
11880 using size_type =
typename BasicJsonType::size_type;
11883 switch (ptr->m_type)
11888 ptr = &ptr->at(reference_token);
11898 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
11899 ") is out of range"));
11903 if (
JSON_UNLIKELY(reference_token.size() > 1 and reference_token[0] ==
'0'))
11906 "array index '" + reference_token +
11907 "' must not begin with '0'"));
11913 ptr = &ptr->at(static_cast<size_type>(
array_index(reference_token)));
#define JSON_CATCH(exception)
array (ordered collection of values)
#define JSON_THROW(exception)
object (unordered set of name/value pairs)
static int array_index(const std::string &s)
static out_of_range create(int id_, const std::string &what_arg)
std::vector< std::string > reference_tokens
the reference tokens
static parse_error create(int id_, const position_t &pos, const std::string &what_arg)
create a parse error exception
template<typename BasicJsonType >
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
-
- Returns
- reference to the JSON value pointed to by the JSON pointer
Linear in the length of the JSON pointer.
- Exceptions
-
| 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 |
Definition at line 11802 of file json.hpp.
References nlohmann::detail::array, nlohmann::detail::parse_error::create(), nlohmann::detail::out_of_range::create(), JSON_CATCH, JSON_THROW, JSON_TRY, JSON_UNLIKELY, nlohmann::detail::null, nlohmann::detail::object, and x.
Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::operator[]().
11804 using size_type =
typename BasicJsonType::size_type;
11812 std::all_of(reference_token.begin(), reference_token.end(),
11815 return (
x >=
'0' and
x <=
'9');
11819 *ptr = (nums or reference_token ==
"-")
11824 switch (ptr->m_type)
11829 ptr = &ptr->operator[](reference_token);
11836 if (
JSON_UNLIKELY(reference_token.size() > 1 and reference_token[0] ==
'0'))
11839 "array index '" + reference_token +
11840 "' must not begin with '0'"));
11843 if (reference_token ==
"-")
11846 ptr = &ptr->operator[](ptr->m_value.array->size());
11853 ptr = &ptr->operator[](
11854 static_cast<size_type
>(
array_index(reference_token)));
#define JSON_CATCH(exception)
array (ordered collection of values)
#define JSON_THROW(exception)
object (unordered set of name/value pairs)
static CCL_BEGIN_DECLS double x[111][8]
static int array_index(const std::string &s)
static out_of_range create(int id_, const std::string &what_arg)
std::vector< std::string > reference_tokens
the reference tokens
static parse_error create(int id_, const position_t &pos, const std::string &what_arg)
create a parse error exception
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
-
- Returns
- const reference to the JSON value pointed to by the JSON pointer
- Exceptions
-
| 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 |
Definition at line 11943 of file json.hpp.
References nlohmann::detail::array, nlohmann::detail::parse_error::create(), nlohmann::detail::out_of_range::create(), JSON_CATCH, JSON_THROW, JSON_TRY, JSON_UNLIKELY, and nlohmann::detail::object.
11945 using size_type =
typename BasicJsonType::size_type;
11948 switch (ptr->m_type)
11953 ptr = &ptr->operator[](reference_token);
11963 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
11964 ") is out of range"));
11968 if (
JSON_UNLIKELY(reference_token.size() > 1 and reference_token[0] ==
'0'))
11971 "array index '" + reference_token +
11972 "' must not begin with '0'"));
11978 ptr = &ptr->operator[](
11979 static_cast<size_type
>(
array_index(reference_token)));
#define JSON_CATCH(exception)
array (ordered collection of values)
#define JSON_THROW(exception)
object (unordered set of name/value pairs)
static int array_index(const std::string &s)
static out_of_range create(int id_, const std::string &what_arg)
std::vector< std::string > reference_tokens
the reference tokens
static parse_error create(int id_, const position_t &pos, const std::string &what_arg)
create a parse error exception
template<typename BasicJsonType >
- Parameters
-
- Returns
- unflattened JSON
- Exceptions
-
| parse_error.109 | if array index is not a number |
| type_error.314 | if value is not an object |
| type_error.315 | if object values are not primitive |
| type_error.313 | if value cannot be unflattened |
Definition at line 12234 of file json.hpp.
References nlohmann::detail::type_error::create(), nlohmann::json_pointer< BasicJsonType >::get_and_create(), JSON_THROW, and JSON_UNLIKELY.
Referenced by nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer >::unflatten().
12241 BasicJsonType result;
12244 for (
const auto& element : *
value.m_value.object)
12255 json_pointer(element.first).get_and_create(result) = element.second;
json_pointer(const std::string &s="")
create JSON pointer
#define JSON_THROW(exception)
auto value(T const &val) -> Generator< T >
static type_error create(int id_, const std::string &what_arg)
template<typename BasicJsonType >
template<template< typename, typename, typename... > class ObjectType, template< typename, typename... > class ArrayType, class StringType , class BooleanType , class NumberIntegerType , class NumberUnsignedType , class NumberFloatType , template< typename > class AllocatorType, template< typename, typename=void > class JSONSerializer>