class
nodethe class that holds a json node which is either ljson::
Constructors, destructors, conversion operators
- node() explicit
- default constructor which creates ljson::
node with type ljson::node_type::object -
node(enum node_
type type) explicit - constructor to allow setting the type of the ljson::
node
Public functions
-
auto as_array() const → std::
shared_ptr<ljson:: array> - access the ljson::
array the ljson:: node is holding, if it exists - auto as_boolean() const → bool
- cast a node into a bool if it is holding ljson::
value that is a json boolean (bool) - auto as_double() const → double
- cast a node into a double if it is holding ljson::
value that is a json number (double) - auto as_integer() const → int64_t
- cast a node into a int64_t if it is holding ljson::
value that is a json number (int64_t) -
auto as_null() const → null_
type - cast a node into a ljson::
null_type if it is holding ljson:: value that is a json null (ljson:: null_type) - auto as_number() const → double
- cast a node into a double if it is holding ljson::
value that is a json number (int64_t or double) -
auto as_object() const → std::
shared_ptr<ljson:: object> - access the ljson::
object the ljson:: node is holding, if it exists -
auto as_string() const → std::
string - cast a node into a string if it is holding ljson::
value that is a json string (ljson:: null_type) -
auto as_value() const → std::
shared_ptr<class value> - access the ljson::
value the ljson:: node is holding, if it exists -
auto at(const std::
string& object_key) const → class node& - access the node at the specified object key
- auto at(const size_t array_index) const → class node&
- access the node at the specified array index
-
auto contains(const std::
string& key) const → bool noexcept - checks if a key exists in a json object
-
auto dump_to_file(const std::
filesystem:: path& path, const std:: pair<char, int>& indent_conf = {' ', 4}) const → expected<monostate, error> - write ljson::
node to a file -
void dump_to_stdout(const std::
pair<char, int>& indent_conf = {' ', 4}) const - write ljson::
node to stdout -
auto dump_to_string(const std::
pair<char, int>& indent_conf = {' ', 4}) const → std:: string - write ljson::
node to string - auto is_array() const → bool noexcept
- checks if ljson::
node is holding ljson:: array - auto is_boolean() const → bool noexcept
- checks if ljson::
node is holding ljson:: value that is holding json boolean (bool) - auto is_double() const → bool noexcept
- checks if ljson::
node is holding ljson:: value that is holding json number (double) - auto is_integer() const → bool noexcept
- checks if ljson::
node is holding ljson:: value that is holding json number (int64_t) - auto is_null() const → bool noexcept
- checks if ljson::
node is holding ljson:: value that is holding json null (ljson:: null_type) - auto is_number() const → bool noexcept
- checks if ljson::
node is holding ljson:: value that is holding json number (double or int64_t) - auto is_object() const → bool noexcept
- checks if ljson::
node is holding ljson:: object - auto is_string() const → bool noexcept
- checks if ljson::
node is holding ljson:: value that is holding json string (std:: string) - auto is_value() const → bool noexcept
- checks if ljson::
node is holding ljson:: value - auto operator+(const node& other_node) → class node
- add two ljson::
node together. they must have the same type and be either object, array, string or number -
template <typename container_or_node_type>auto operator=(const container_or_node_type& node_value) → class node& noexcept
- asign a node with a container_or_node_type
-
template <typename container_or_node_type>void set(const container_or_node_type& node_value) noexcept
- set a node with a container_or_node_type
-
auto stringify() const → std::
string noexcept - stringify the json (object, array or value) inside the ljson::
node -
auto try_as_array() const → expected<std::
shared_ptr<ljson:: array>, error> noexcept - access the ljson::
array the ljson:: node is holding, if it exists - auto try_as_boolean() const → expected<bool, error> noexcept
- cast a node into a bool if it is holding ljson::
value that is a json boolean (bool) - auto try_as_double() const → expected<double, error> noexcept
- cast a node into a double if it is holding ljson::
value that is a json number (double) - auto try_as_integer() const → expected<int64_t, error> noexcept
- cast a node into a int64_t if it is holding ljson::
value that is a json number (int64_t) -
auto try_as_null() const → expected<null_
type, error> noexcept - cast a node into a ljson::
null_type if it is holding ljson:: value that is a json null - auto try_as_number() const → expected<double, error> noexcept
- cast a node into a double if it is holding ljson::
value that is a json number (double or int64_t) -
auto try_as_object() const → expected<std::
shared_ptr<ljson:: object>, error> noexcept - access the ljson::
object the ljson:: node is holding, if it exists -
auto try_as_string() const → expected<std::
string, error> noexcept - cast a node into a std::
string if it is holding ljson:: value that is a json string (std:: string) -
auto try_as_value() const → expected<std::
shared_ptr<class value>, error> noexcept - access the ljson::
value the ljson:: node is holding, if it exists -
auto try_at(const std::
string& object_key) const → expected<std:: reference_wrapper<ljson:: node>, ljson:: error> noexcept - access the node at the specified object key
-
auto try_at(const size_t array_index) const → expected<std::
reference_wrapper<ljson:: node>, ljson:: error> noexcept - access the node at the specified array index
-
auto type() const → node_
type noexcept - gets the ljson::
node_type of the internal node -
auto type_name() const → std::
string noexcept - gets string representation of ljson::
node_type of the internal node -
auto value_type_name() const → std::
string noexcept - gets string representation of ljson::value_type of the internal node if it's holding ljson::
value - auto valuetype() const → value_type noexcept
- gets the ljson::value_type of the node if it's holding ljson::
value. otherwise it returns value_type::none
Function documentation
ljson:: node:: node(enum node_ type type) explicit
constructor to allow setting the type of the ljson::
Parameters | |
---|---|
type | type of node from enum ljson:: |
std:: shared_ptr<ljson:: array> ljson:: node:: as_array() const
access the ljson::
Returns | std:: |
---|---|
Exceptions | |
ljson:: |
if it doesn't hold ljson:: |
bool ljson:: node:: as_boolean() const
cast a node into a bool if it is holding ljson::
Returns | json boolean |
---|---|
Exceptions | |
ljson:: |
if it doesn't hold a ljson:: |
double ljson:: node:: as_double() const
cast a node into a double if it is holding ljson::
Returns | json number |
---|---|
Exceptions | |
ljson:: |
if it doesn't hold a ljson:: |
int64_t ljson:: node:: as_integer() const
cast a node into a int64_t if it is holding ljson::
Returns | json number |
---|---|
Exceptions | |
ljson:: |
if it doesn't hold a ljson:: |
null_ type ljson:: node:: as_null() const
cast a node into a ljson::
Returns | json null |
---|---|
Exceptions | |
ljson:: |
if it doesn't hold a ljson:: |
double ljson:: node:: as_number() const
cast a node into a double if it is holding ljson::
Returns | json number |
---|---|
Exceptions | |
ljson:: |
if it doesn't hold a ljson:: |
std:: shared_ptr<ljson:: object> ljson:: node:: as_object() const
access the ljson::
Returns | std:: |
---|---|
Exceptions | |
ljson:: |
if it doesn't hold ljson:: |
std:: string ljson:: node:: as_string() const
cast a node into a string if it is holding ljson::
Returns | json string |
---|---|
Exceptions | |
ljson:: |
if it doesn't hold a ljson:: |
std:: shared_ptr<class value> ljson:: node:: as_value() const
access the ljson::
Returns | std:: |
---|---|
Exceptions | |
ljson:: |
if it doesn't hold ljson:: |
class node& ljson:: node:: at(const std:: string& object_key) const
access the node at the specified object key
Parameters | |
---|---|
object_key | json key to access in an object |
Returns | ljson:: |
class node& ljson:: node:: at(const size_t array_index) const
access the node at the specified array index
Parameters | |
---|---|
array_index | json index to access in an array |
Returns | ljson:: |
bool ljson:: node:: contains(const std:: string& key) const noexcept
checks if a key exists in a json object
Parameters | |
---|---|
key | key to lookup |
Returns | true if it does |
expected<monostate, error> ljson:: node:: dump_to_file(const std:: filesystem:: path& path,
const std:: pair<char, int>& indent_conf = {' ', 4}) const
write ljson::
Parameters | |
---|---|
path | path to write to |
indent_conf | indentation config for writing {char, size} |
void ljson:: node:: dump_to_stdout(const std:: pair<char, int>& indent_conf = {' ', 4}) const
write ljson::
Parameters | |
---|---|
indent_conf | indentation config for writing {char, size} |
std:: string ljson:: node:: dump_to_string(const std:: pair<char, int>& indent_conf = {' ', 4}) const
write ljson::
Parameters | |
---|---|
indent_conf | indentation config for writing {char, size} |
Returns | json serialized |
bool ljson:: node:: is_array() const noexcept
checks if ljson::
Returns | true if it does |
---|
bool ljson:: node:: is_boolean() const noexcept
checks if ljson::
Returns | true if it does |
---|
bool ljson:: node:: is_double() const noexcept
checks if ljson::
Returns | true if it does |
---|
bool ljson:: node:: is_integer() const noexcept
checks if ljson::
Returns | true if it does |
---|
bool ljson:: node:: is_null() const noexcept
checks if ljson::
Returns | true if it does |
---|
bool ljson:: node:: is_number() const noexcept
checks if ljson::
Returns | true if it does |
---|
bool ljson:: node:: is_object() const noexcept
checks if ljson::
Returns | true if it does |
---|
bool ljson:: node:: is_string() const noexcept
checks if ljson::
Returns | true if it does |
---|
bool ljson:: node:: is_value() const noexcept
checks if ljson::
Returns | true if it does |
---|
ljson::node node(ljson::node_type::value); if (node.is_value()) { // do something }
class node ljson:: node:: operator+(const node& other_node)
add two ljson::
Parameters | |
---|---|
other_node | the other node to add to the current node |
Returns | new node containing content of both nodes |
Exceptions | |
ljson:: |
if different types or not one of the required types |
ljson::node new_node = node1 + node2;
{"node1_key": "node1_value"}
{"node2_key": "node2_value"}
{"node1_key": "node1_value", "node2_key": "node2_value"}
std:: string ljson:: node:: stringify() const noexcept
stringify the json (object, array or value) inside the ljson::
Returns | serialized json |
---|
{ "key1": "val1", "key2": "val2" }
[ "val1", "val2", "val3" ]
value
expected<std:: shared_ptr<ljson:: array>, error> ljson:: node:: try_as_array() const noexcept
access the ljson::
Returns | ljson:: |
---|
expected<bool, error> ljson:: node:: try_as_boolean() const noexcept
cast a node into a bool if it is holding ljson::
Returns | bool or ljson:: |
---|
expected<double, error> ljson:: node:: try_as_double() const noexcept
cast a node into a double if it is holding ljson::
Returns | double or ljson:: |
---|
expected<int64_t, error> ljson:: node:: try_as_integer() const noexcept
cast a node into a int64_t if it is holding ljson::
Returns | int64_t or ljson:: |
---|
expected<null_ type, error> ljson:: node:: try_as_null() const noexcept
cast a node into a ljson::
Returns | ljson:: |
---|
ljson::expected<null_type, error> null = node.try_as_null(); if (not null) { // handle error std::println("{}", null.error().message()); } else { // success ljson::null_type null_value = null.value(); }
expected<double, error> ljson:: node:: try_as_number() const noexcept
cast a node into a double if it is holding ljson::
Returns | double or ljson:: |
---|
expected<std:: shared_ptr<ljson:: object>, error> ljson:: node:: try_as_object() const noexcept
access the ljson::
Returns | ljson:: |
---|
expected<std:: string, error> ljson:: node:: try_as_string() const noexcept
cast a node into a std::
Returns | std:: |
---|
ljson::expected<std::string, error> string = node.try_as_string(); if (not string) { // handle error std::println("{}", string.error().message()); } else { // success std::string string_value = string.value(); }
expected<std:: shared_ptr<class value>, error> ljson:: node:: try_as_value() const noexcept
access the ljson::
Returns | ljson:: |
---|
expected<std:: reference_wrapper<ljson:: node>, ljson:: error> ljson:: node:: try_at(const std:: string& object_key) const noexcept
access the node at the specified object key
Parameters | |
---|---|
object_key | json key to access in an object |
Returns | either std:: |
ljson::expected<std::reference_wrapper<ljson::node>, ljson::error> maybe_node = object_node.try_at("key"); if (maybe_node) { // notice the '&' is neccessary if this reference would be used to modify // the value inside ljson::node& node_at_key = maybe_node.value().get(); // .value() to get the expected type, .get() for the node reference // or you can set it like this to avoid forgetting the '&' maybe_node.value().get().set(std::string("new value")); } else { std::println("{}", maybe_node.error().message()); }
expected<std:: reference_wrapper<ljson:: node>, ljson:: error> ljson:: node:: try_at(const size_t array_index) const noexcept
access the node at the specified array index
Parameters | |
---|---|
array_index | json index to access in an array |
Returns | either std:: |
ljson::expected<std::reference_wrapper<ljson::node>, ljson::error> maybe_node = array_node.try_at(0); if (maybe_node) { // notice the '&' is neccessary if this reference would be used to modify // the value inside ljson::node& node_at_key = maybe_node.value().get(); // .value() to get the expected type, .get() for the node reference // or you can set it like this to avoid forgetting the '&' maybe_node.value().get().set(true); } else { std::println("{}", maybe_node.error().message()); }
node_ type ljson:: node:: type() const noexcept
gets the ljson::
Returns | node_type |
---|
std:: string ljson:: node:: type_name() const noexcept
gets string representation of ljson::
Returns | string name of the node_type |
---|
std:: string ljson:: node:: value_type_name() const noexcept
gets string representation of ljson::value_type of the internal node if it's holding ljson::
Returns | string name of the value_type |
---|
value_type ljson:: node:: valuetype() const noexcept
gets the ljson::value_type of the node if it's holding ljson::
Returns | value_type |
---|