Class Value

#include <matjson.hpp>
classValue{ ... }
No description provided
Examples0
Public static methods4
staticmatjson::Valueobject()

Create an empty JSON object

staticmatjson::Valuearray()

Create an empty JSON array

staticgeode::Result<matjson::Value,matjson::ParseError>parse()

Parses JSON from a string

Parameters

source

The JSON string to parse
Return value
The parsed JSON value or an error
staticgeode::Result<matjson::Value,matjson::ParseError>parse()

Parses JSON from an input stream

Parameters

source

Stream to parse
Return value
The parsed JSON value or an error
Public member functions49
template<class T>voidValue(
Tvalue
)
No description provided
template<class T>voidValue(
Tvalue
)
No description provided
template<CanSerialize T>voidValue(
T&&value
)
No description provided
template<class T>voidValue()
No description provided
matjson::Value&operator=()
No description provided
booloperator==()const
No description provided
booloperator<()const
No description provided
booloperator>()const
No description provided
std::stringdump(
intindentationSize
)
const

Dumps the JSON value to a string, with a given indentation. If the given indentation is matjson::NO_INDENTATION, the json is compacted. If the given indentation is matjson::TAB_INDENTATION, the json is indented with tabs.

Parameters

indentationSize

The number of spaces to use for indentation
Return value
The JSON string

ℹ Due to limitations in the JSON format, NaN and Infinity float values get converted to null. This behavior is the same as many other JSON libraries.

geode::Result<matjson::Value&>get()

Returns the value associated with the given key

Parameters

key

Object key
Return value
The value associated with the key, or an error if it does not exist.
geode::Result<matjson::Valueconst&>get()const

Returns the value associated with the given key

Parameters

key

Object key
Return value
The value associated with the key, or an error if it does not exist.
geode::Result<matjson::Value&>get()

Returns the value associated with the given index

Parameters

index

Array index
Return value
The value associated with the index, or an error if the index is out of bounds.
geode::Result<matjson::Valueconst&>get()const

Returns the value associated with the given index

Parameters

index

Array index
Return value
The value associated with the index, or an error if the index is out of bounds.
matjson::Value&operator[]()

Returns the value associated with the given key

Parameters

key

Object key
Return value
The value associated with the key

ℹ If the key does not exist, it is inserted into the object. And if this is not an object, returns a null value

matjson::Valueconst&operator[]()const

Returns the value associated with the given key

Parameters

key

Object key
Return value
The value associated with the key

ℹ If the key does not exist, or this is not an object, returns a null value

matjson::Value&operator[]()

Returns the value associated with the given index

Parameters

index

Array index
Return value
The value associated with the index

ℹ If the index is out of bounds, or this is not an array, returns a null value

matjson::Valueconst&operator[]()const

Returns the value associated with the given index

Parameters

index

Array index
Return value
The value associated with the index

ℹ If the index is out of bounds, or this is not an array, returns a null value

voidset(,)

Sets the value associated with the given key

Parameters

key

Object key

value

The value to set

ℹ If this is not an object, nothing happens

voidpush()

Adds a value to the end of the array

Parameters

value

Value

ℹ If this is not an array, nothing happens

voidclear()

Clears the array/object, removing all entries

ℹ If this is not an array or object, nothing happens

boolerase()

Removes the value associated with the given key

Parameters

key

Object key
Return value
true if the key was removed, false otherwise

ℹ If this is not an object, nothing happens and returns false

boolcontains()const

Checks if the key exists in the object

Parameters

key

Object key
Return value
true if the key exists, false otherwise

ℹ If this is not an object, returns false

std::size_tsize()const

Returns the number of entries in the array/object.

Return value
The number of entries

ℹ If this is not an array or object, returns 0

matjson::Typetype()const

Returns the type of the JSON value

std::optional<std::string>getKey()const

Returns the key of the object entry, if it is one. If this is not an entry in an object, returns an empty optional.

Return value
The key of the object entry
std::vector::iteratorbegin()
No description provided
std::vector::iteratorend()
No description provided
std::vector::const_iteratorbegin()const
No description provided
std::vector::const_iteratorend()const
No description provided
boolisNull()const
No description provided
boolisString()const
No description provided
boolisNumber()const
No description provided
boolisBool()const
No description provided
boolisArray()const
No description provided
boolisObject()const
No description provided
boolisExactlyDouble()const

Returns true if the number stored is a double, false otherwise. This depends on how the value is stored internally.

ℹ This is useful for checking if the number is an integer or a double.

boolisExactlyInt()const

Returns true if the number stored is a signed integer, false otherwise. This depends on how the value is stored internally.

ℹ This is useful for checking if the number is an integer or a double.

boolisExactlyUInt()const

Returns true if the number stored is an unsigned integer, false otherwise. This depends on how the value is stored internally.

ℹ This is useful for checking if the number is an integer or a double.

geode::Result<bool>asBool()const

Returns the number as a boolean, if this is a boolean. If this is not a boolean, returns an error.

geode::Result<std::string>asString()const

Returns the number as a string, if this is a string. If this is not a string, returns an error.

geode::Result<std::intmax_t>asInt()const

Returns the number as a signed integer, if this is a number. If this is not a number, returns an error.

geode::Result<std::uintmax_t>asUInt()const

Returns the number as an unsigned integer, if this is a number. If this is not a number, returns an error.

geode::Result<double>asDouble()const

Returns the number as a double, if this is a number. If this is not a number, returns an error.

geode::Result<std::vector<matjson::Value>&>asArray()

Returns a reference to the array, if this is an array. If this is not an array, returns an error.

geode::Result<std::vector<matjson::Value>>asArray()

Returns the array, if this is an array. If this is not an array, returns an error.

geode::Result<std::vector<matjson::Value>const&>asArray()const

Returns a reference to the array, if this is an array. If this is not an array, returns an error.

template<class T>autoas()const

Converts the JSON value to a given type, possibly serializing to a custom type via the Serialize specialization

Template parameters

T

The type to convert to
Return value
The converted value or an error
template<class T,class Key>autoget(
Key&&keyOrIndex
)

Gets the value from a key/index, and converts it to T

Parameters

keyOrIndex

The key or index to get the value from
Template parameters

T

The type to convert to
Return value
The converted value or an error

ℹ Shorthand for get(key).as<T>()

template<class T,class Key>autoget(
Key&&keyOrIndex
)
const

Gets the value from a key/index, and converts it to T

Parameters

keyOrIndex

The key or index to get the value from
Template parameters

T

The type to convert to
Return value
The converted value or an error

ℹ Shorthand for get(key).as<T>()

Fields0
Protected member functions0
Protected fields0