#include <userver/formats/json/value.hpp>
Non-mutable JSON value representation.
Class provides non mutable access JSON value. For modification and construction of new JSON values use formats::json::ValueBuilder.
Classes | |
| struct | DefaultConstructed |
| struct | IterTraits |
Public Member Functions | |
| Value () | |
| Constructs a Value that holds a null. | |
| Value (const Value &)=default | |
| Value (Value &&) noexcept | |
| Value & | operator= (const Value &) &=default |
| Value & | operator= (Value &&) noexcept |
| template<class T > | |
| Value & | operator= (T &&) && |
| Value | operator[] (std::string_view key) const |
| Access member by key for read. | |
| Value | operator[] (std::size_t index) const |
| Access array member by index for read. | |
| const_iterator | begin () const |
| Returns an iterator to the beginning of the held array or map. | |
| const_iterator | end () const |
| Returns an iterator to the end of the held array or map. | |
| const_reverse_iterator | rbegin () const |
| Returns an iterator to the reversed begin of the held array. | |
| const_reverse_iterator | rend () const |
| Returns an iterator to the reversed end of the held array. | |
| bool | IsEmpty () const |
| Returns whether the array or object is empty. Returns true for null. | |
| std::size_t | GetSize () const |
| Returns array size, object members count, or 0 for null. | |
| bool | operator== (const Value &other) const |
| Compares values. | |
| bool | operator!= (const Value &other) const |
| bool | IsMissing () const noexcept |
Returns true if *this holds nothing. When IsMissing() returns true any attempt to get the actual value or iterate over *this will. | |
| bool | IsNull () const noexcept |
| Returns true if *this holds a null (Type::kNull). | |
| bool | IsBool () const noexcept |
| Returns true if *this holds a bool. | |
| bool | IsInt () const noexcept |
| Returns true if *this holds an int. | |
| bool | IsInt64 () const noexcept |
| Returns true if *this holds an int64_t. | |
| bool | IsUInt64 () const noexcept |
| Returns true if *this holds an uint64_t. | |
| bool | IsDouble () const noexcept |
| Returns true if *this holds a double. | |
| bool | IsString () const noexcept |
| Returns true if *this is holds a std::string. | |
| bool | IsArray () const noexcept |
| Returns true if *this is holds an array (Type::kArray). | |
| bool | IsObject () const noexcept |
| Returns true if *this holds a map (Type::kObject). | |
| template<typename T > | |
| auto | As () const |
| Returns value of *this converted to the result type of Parse(const Value&, parse::To<T>). Almost always it is T. | |
| template<typename T , typename First , typename... Rest> | |
| auto | As (First &&default_arg, Rest &&... more_default_args) const |
| Returns value of *this converted to T or T(args) if this->IsMissing(). | |
| template<typename T > | |
| auto | As (DefaultConstructed) const |
| Returns value of *this converted to T or T() if this->IsMissing(). | |
| template<typename T > | |
| T | ConvertTo () const |
Extracts the specified type with relaxed type checks. For example, true may be converted to 1.0. | |
| template<typename T , typename First , typename... Rest> | |
| T | ConvertTo (First &&default_arg, Rest &&... more_default_args) const |
| bool | HasMember (std::string_view key) const |
Returns true if *this holds a key. | |
| std::string | GetPath () const |
| Returns full path to this value. | |
| Value | Clone () const |
| Returns new value that is an exact copy of the existing one but references different memory (a deep copy of a *this). The returned value is a root value with path '/'. | |
| void | CheckNotMissing () const |
| void | CheckArrayOrNull () const |
| void | CheckObjectOrNull () const |
| void | CheckObject () const |
| void | CheckObjectOrArrayOrNull () const |
| void | CheckInBounds (std::size_t index) const |
| bool | IsRoot () const noexcept |
| Returns true if *this is a first (root) value. | |
| bool | DebugIsReferencingSameMemory (const Value &other) const |
Returns true if *this and other reference the value by the same pointer. | |
| template<> | |
| bool | ConvertTo () const |
| template<> | |
| int64_t | ConvertTo () const |
| template<> | |
| uint64_t | ConvertTo () const |
| template<> | |
| double | ConvertTo () const |
Returns value of *this converted to the result type of Parse(const Value&, parse::To<T>). Almost always it is T.
| Anything | derived from std::exception. |
| auto formats::json::Value::As | ( | Value::DefaultConstructed | ) | const |
Returns value of *this converted to T or T() if this->IsMissing().
| Anything | derived from std::exception. |
value.As<T>({}) Returns value of *this converted to T or T(args) if this->IsMissing().
| Anything | derived from std::exception. |
| const_iterator formats::json::Value::begin | ( | ) | const |
Returns an iterator to the beginning of the held array or map.
| TypeMismatchException | if not an array, object, or null. |
| void formats::json::Value::CheckArrayOrNull | ( | ) | const |
| MemberMissingException | if *this is not an array or null. |
| void formats::json::Value::CheckInBounds | ( | std::size_t | index | ) | const |
| TypeMismatchException | if *this is not a map, array or null; OutOfBoundsException if index >= this->GetSize(). |
| void formats::json::Value::CheckNotMissing | ( | ) | const |
| MemberMissingException | if this->IsMissing(). |
| void formats::json::Value::CheckObject | ( | ) | const |
| TypeMismatchException | if *this is not a map. |
| void formats::json::Value::CheckObjectOrArrayOrNull | ( | ) | const |
| TypeMismatchException | if *this is not a map, array or null. |
| void formats::json::Value::CheckObjectOrNull | ( | ) | const |
| TypeMismatchException | if *this is not a map or null. |
| Value formats::json::Value::Clone | ( | ) | const |
Returns new value that is an exact copy of the existing one but references different memory (a deep copy of a *this). The returned value is a root value with path '/'.
| MemberMissingException | if this->IsMissing(). |
| T formats::json::Value::ConvertTo | ( | ) | const |
| T formats::json::Value::ConvertTo | ( | First && | default_arg, |
| Rest &&... | more_default_args ) const |
| const_iterator formats::json::Value::end | ( | ) | const |
Returns an iterator to the end of the held array or map.
| TypeMismatchException | if not an array, object, or null. |
| std::size_t formats::json::Value::GetSize | ( | ) | const |
Returns array size, object members count, or 0 for null.
| TypeMismatchException | if not an array, object, or null. |
| bool formats::json::Value::HasMember | ( | std::string_view | key | ) | const |
Returns true if *this holds a key.
| TypeMismatchException | if *this is not a map or null. |
| bool formats::json::Value::IsEmpty | ( | ) | const |
Returns whether the array or object is empty. Returns true for null.
| TypeMismatchException | if not an array, object, or null. |
|
inline |
| bool formats::json::Value::operator== | ( | const Value & | other | ) | const |
Compares values.
| MemberMissingException | if *this or other is missing. |
| Value formats::json::Value::operator[] | ( | std::size_t | index | ) | const |
Access array member by index for read.
| TypeMismatchException | if not an array value. |
| OutOfBoundsException | if index is greater or equal than size. |
| Value formats::json::Value::operator[] | ( | std::string_view | key | ) | const |
Access member by key for read.
| TypeMismatchException | if not a missing value, an object or null. |
| const_reverse_iterator formats::json::Value::rbegin | ( | ) | const |
Returns an iterator to the reversed begin of the held array.
| TypeMismatchException | if not an array or null. |
| const_reverse_iterator formats::json::Value::rend | ( | ) | const |
Returns an iterator to the reversed end of the held array.
| TypeMismatchException | if not an array or null. |
|
friend |
Parse JSON from string.
Definition at line 88 of file from_string.hpp.
|
friend |
|
friend |
|
friend |
|
friend |
Stably serialize JSON to string. In result there is no whitespace, keys are sorted and character escaping is stabilized
|
friend |