Non-mutable JSON value representation. More...
#include <userver/formats/json/value.hpp>
Classes | |
struct | DefaultConstructed |
struct | IterTraits |
Public Types | |
using | const_iterator = Iterator< IterTraits, common::IteratorDirection::kForward > |
using | const_reverse_iterator = Iterator< IterTraits, common::IteratorDirection::kReverse > |
using | Exception = formats::json::Exception |
using | ParseException = formats::json::ParseException |
using | Builder = ValueBuilder |
Public Member Functions | |
Value () noexcept=default | |
Constructs a Value that holds a null. | |
Value (const Value &)=default | |
Value (Value &&) noexcept=default | |
Value & | operator= (const Value &) &=default |
Value & | operator= (Value &&other) &noexcept=default |
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 > | |
T | As () const |
Returns value of *this converted to T. | |
template<typename T , typename First , typename... Rest> | |
T | 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 > | |
T | 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 if 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 | As () const |
template<> | |
int64_t | As () const |
template<> | |
uint64_t | As () const |
template<> | |
double | As () const |
template<> | |
bool | ConvertTo () const |
template<> | |
int64_t | ConvertTo () const |
template<> | |
uint64_t | ConvertTo () const |
template<> | |
double | ConvertTo () const |
Friends | |
template<typename , common::IteratorDirection > | |
class | Iterator |
class | ValueBuilder |
class | StringBuilder |
class | parser::JsonValueParser |
formats::json::Value | FromString (std::string_view) |
Parse JSON from string. | |
formats::json::Value | FromStream (std::istream &) |
Parse JSON from stream. | |
void | Serialize (const formats::json::Value &, std::ostream &) |
Serialize JSON to stream. | |
std::string | ToString (const formats::json::Value &) |
Serialize JSON to string. | |
std::string | ToStableString (const formats::json::Value &) |
std::string | ToStableString (formats::json::Value &&) |
logging::LogHelper & | operator<< (logging::LogHelper &, const Value &) |
Log JSON. | |
Non-mutable JSON value representation.
Class provides non mutable access JSON value. For modification and construction of new JSON values use formats::json::ValueBuilder.
using formats::json::Value::const_iterator = Iterator<IterTraits, common::IteratorDirection::kForward> |
using formats::json::Value::const_reverse_iterator = Iterator<IterTraits, common::IteratorDirection::kReverse> |
T formats::json::Value::As | ( | ) | const |
Returns value of *this converted to T.
Anything | derived from std::exception. |
T 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>({})
T formats::json::Value::As | ( | First && | default_arg, |
Rest &&... | more_default_args | ||
) | const |
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 if the existing one but references different memory (a deep copy of a *this). The returned value is a root value with path '/'.
MemberMissingException | id 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 87 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 |