Create an empty JSON object
Class Value
#include <matjson.hpp>
Examples0
Public static methods4
staticmatjson::Valueobject()
staticmatjson::Valuearray()
Create an empty JSON array
staticgeode::Result<matjson::Value,matjson::ParseError>parse(std::string_viewsource)
Parses JSON from a string
source
staticgeode::Result<matjson::Value,matjson::ParseError>parse(std::istream&source)
Parses JSON from an input stream
source
Public member functions49
matjson::Value&operator=()
booloperator==()const
booloperator<()const
booloperator>()const
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.
indentationSize
ℹ 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
key
geode::Result<matjson::Valueconst&>get()const
Returns the value associated with the given key
key
geode::Result<matjson::Value&>get(std::size_tindex)
Returns the value associated with the given index
index
geode::Result<matjson::Valueconst&>get(std::size_tindex)const
Returns the value associated with the given index
index
matjson::Value&operator[]()
Returns the value associated with the given key
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
key
ℹ If the key does not exist, or this is not an object, returns a null value
matjson::Value&operator[](std::size_tindex)
Returns the value associated with the given index
index
ℹ If the index is out of bounds, or this is not an array, returns a null value
matjson::Valueconst&operator[](std::size_tindex)const
Returns the value associated with the given index
index
ℹ If the index is out of bounds, or this is not an array, returns a null value
voidset(,matjson::Valuevalue)
Sets the value associated with the given key
key
value
ℹ If this is not an object, nothing happens
voidpush(matjson::Valuevalue)
Adds a value to the end of the array
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
key
ℹ If this is not an object, nothing happens and returns false
boolcontains()const
Checks if the key exists in the object
key
ℹ If this is not an object, returns false
std::size_tsize()const
Returns the number of entries in the array/object.
ℹ 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.
std::vector::iteratorbegin()
std::vector::iteratorend()
std::vector::const_iteratorbegin()const
std::vector::const_iteratorend()const
boolisNull()const
boolisString()const
boolisNumber()const
boolisBool()const
boolisArray()const
boolisObject()const
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
T