actor-framework
Public Member Functions | Static Public Member Functions | Friends | Related Functions | List of all members
caf::json_value Class Reference

Represents an immutable JSON value. More...

#include <json_value.hpp>

Public Member Functions

 json_value () noexcept
 Creates a null JSON value.
 
 json_value (const detail::json::value *val, detail::json::storage_ptr sptr) noexcept
 
 json_value (json_value &&) noexcept=default
 
 json_value (const json_value &) noexcept=default
 
json_valueoperator= (json_value &&) noexcept=default
 
json_valueoperator= (const json_value &) noexcept=default
 
bool is_null () const noexcept
 Checks whether the value is null.
 
bool is_undefined () const noexcept
 Checks whether the value is undefined. More...
 
bool is_integer () const noexcept
 Checks whether the value is an int64_t.
 
bool is_unsigned () const noexcept
 Checks whether the value is an uint64_t.
 
bool is_double () const noexcept
 Checks whether the value is a double.
 
bool is_number () const noexcept
 Checks whether the value is a number, i.e., an int64_t, a uint64_t or a double. More...
 
bool is_bool () const noexcept
 Checks whether the value is a bool.
 
bool is_string () const noexcept
 Checks whether the value is a JSON string (std::string_view).
 
bool is_array () const noexcept
 Checks whether the value is an JSON array.
 
bool is_object () const noexcept
 Checks whether the value is a JSON object.
 
int64_t to_integer (int64_t fallback=0) const
 Converts the value to an int64_t or returns fallback if the value is not a valid number. More...
 
uint64_t to_unsigned (uint64_t fallback=0) const
 Converts the value to an uint64_t or returns fallback if the value is not a valid number. More...
 
double to_double (double fallback=0.0) const
 Converts the value to a double or returns fallback if the value is not a valid number. More...
 
bool to_bool (bool fallback=false) const
 Converts the value to a bool or returns fallback if the value is not a valid boolean. More...
 
std::string_view to_string () const
 Returns the value as a JSON string or an empty string if the value is not a string. More...
 
std::string_view to_string (std::string_view fallback) const
 Returns the value as a JSON string or fallback if the value is not a string. More...
 
json_array to_array () const
 Returns the value as a JSON array or an empty array if the value is not an array. More...
 
json_array to_array (json_array fallback) const
 Returns the value as a JSON array or fallback if the value is not an array. More...
 
json_object to_object () const
 Returns the value as a JSON object or an empty object if the value is not an object. More...
 
json_object to_object (json_object fallback) const
 Returns the value as a JSON object or fallback if the value is not an object. More...
 
bool equal_to (const json_value &other) const noexcept
 Compares two JSON values for equality.
 
template<class Buffer >
void print_to (Buffer &buf, size_t indentation_factor=0) const
 Prints the JSON value to buf.
 

Static Public Member Functions

static json_value undefined () noexcept
 Creates an undefined JSON value. More...
 
static expected< json_valueparse (std::string_view str)
 Attempts to parse str as JSON input into a self-contained value.
 
static expected< json_valueparse_shallow (std::string_view str)
 Attempts to parse str as JSON input into a value that avoids copies where possible by pointing into str. More...
 
static expected< json_valueparse_in_situ (std::string &str)
 Attempts to parse str as JSON input. More...
 
static expected< json_valueparse_file (const char *path)
 Attempts to parse the content of the file at path as JSON input into a self-contained value. More...
 
static expected< json_valueparse_file (const std::string &path)
 Attempts to parse the content of the file at path as JSON input into a self-contained value. More...
 

Friends

template<class Inspector >
bool inspect (Inspector &inspector, json_value &val)
 Applies the Inspector to the JSON value val.
 

Related Functions

(Note that these are not member functions.)

CAF_CORE_EXPORT std::string to_string (const json_value &val)
 

Detailed Description

Represents an immutable JSON value.

Member Function Documentation

◆ is_number()

bool caf::json_value::is_number ( ) const
noexcept

Checks whether the value is a number, i.e., an int64_t, a uint64_t or a double.

◆ is_undefined()

bool caf::json_value::is_undefined ( ) const
inlinenoexcept

Checks whether the value is undefined.

This special state indicates that a previous key lookup failed.

◆ parse_file() [1/2]

expected< json_value > caf::json_value::parse_file ( const char *  path)
static

Attempts to parse the content of the file at path as JSON input into a self-contained value.

◆ parse_file() [2/2]

expected< json_value > caf::json_value::parse_file ( const std::string &  path)
static

Attempts to parse the content of the file at path as JSON input into a self-contained value.

◆ parse_in_situ()

expected< json_value > caf::json_value::parse_in_situ ( std::string &  str)
static

Attempts to parse str as JSON input.

Decodes JSON in place and points back into the str for all strings in the JSON input.

Warning
The returned json_value may hold pointers into str. Thus, the input must outlive the json_value and any other JSON objects created from that value.

◆ parse_shallow()

expected< json_value > caf::json_value::parse_shallow ( std::string_view  str)
static

Attempts to parse str as JSON input into a value that avoids copies where possible by pointing into str.

Warning
The returned json_value may hold pointers into str. Thus, the input must outlive the json_value and any other JSON objects created from that value.

◆ to_array() [1/2]

json_array caf::json_value::to_array ( ) const

Returns the value as a JSON array or an empty array if the value is not an array.

◆ to_array() [2/2]

json_array caf::json_value::to_array ( json_array  fallback) const

Returns the value as a JSON array or fallback if the value is not an array.

◆ to_bool()

bool caf::json_value::to_bool ( bool  fallback = false) const

Converts the value to a bool or returns fallback if the value is not a valid boolean.

◆ to_double()

double caf::json_value::to_double ( double  fallback = 0.0) const

Converts the value to a double or returns fallback if the value is not a valid number.

◆ to_integer()

int64_t caf::json_value::to_integer ( int64_t  fallback = 0) const

Converts the value to an int64_t or returns fallback if the value is not a valid number.

◆ to_object() [1/2]

json_object caf::json_value::to_object ( ) const

Returns the value as a JSON object or an empty object if the value is not an object.

◆ to_object() [2/2]

json_object caf::json_value::to_object ( json_object  fallback) const

Returns the value as a JSON object or fallback if the value is not an object.

◆ to_string() [1/2]

std::string_view caf::json_value::to_string ( ) const

Returns the value as a JSON string or an empty string if the value is not a string.

◆ to_string() [2/2]

std::string_view caf::json_value::to_string ( std::string_view  fallback) const

Returns the value as a JSON string or fallback if the value is not a string.

◆ to_unsigned()

uint64_t caf::json_value::to_unsigned ( uint64_t  fallback = 0) const

Converts the value to an uint64_t or returns fallback if the value is not a valid number.

◆ undefined()

json_value caf::json_value::undefined ( )
staticnoexcept

Creates an undefined JSON value.

This special state usually indicates that a previous key lookup failed.

Friends And Related Function Documentation

◆ to_string()

CAF_CORE_EXPORT std::string to_string ( const json_value val)
related

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