Non-mutable JSON value representation.
Class provides non mutable access JSON value. For modification and construction of new JSON values use formats::json::ValueBuilder.
Example usage:
"key1": 1,
"key2": {"key3":"val"}
})");
const auto key1 = json["key1"].As<int>();
ASSERT_EQ(key1, 1);
const auto key3 = json["key2"]["key3"].As<std::string>();
ASSERT_EQ(key3, "val");
- See also
- Formats (JSON, YAML, BSON, ...)
- Examples
- samples/config_service/config_service.cpp, samples/http_caching/http_caching.cpp, samples/kafka_service/src/producer_handler.cpp, samples/kafka_service/src/producer_handler.hpp, samples/testsuite-support/src/logcapture.cpp, samples/testsuite-support/src/metrics.cpp, samples/testsuite-support/src/metrics.hpp, samples/testsuite-support/src/now.cpp, and samples/testsuite-support/src/testpoint.cpp.
Definition at line 58 of file value.hpp.
|
| 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 |
|