Convenient JSON object parser.
More...
#include <json_util.hpp>
|
| deserializer (const nlohmann::json &obj) |
|
template<typename Type > |
auto | get (const std::string &key) const noexcept -> std::optional< Type > |
|
template<typename Type , typename DefaultValue > |
auto | optional (const std::string &key, DefaultValue &&def) const noexcept -> std::optional< Type > |
|
Convenient JSON object parser.
This class helps destructuring insecure JSON input by returning optional values if they are not present or invalid.
◆ deserializer()
irccd::json_util::deserializer::deserializer |
( |
const nlohmann::json & |
obj | ) |
|
◆ get()
template<typename Type >
auto irccd::json_util::deserializer::get |
( |
const std::string & |
key | ) |
const -> std::optional<Type>
|
|
inlinenoexcept |
Get a value from the document object.
- Parameters
-
- Returns
- the value or std::nullopt if not found or not convertible
◆ optional()
template<typename Type , typename DefaultValue >
auto irccd::json_util::deserializer::optional |
( |
const std::string & |
key, |
|
|
DefaultValue && |
def |
|
) |
| const -> std::optional<Type>
|
|
inlinenoexcept |
Get an optional value from the document object.
If the value is undefined, the default value is returned. Otherwise, if the value is not in the given type, std::nullopt is returned.
- Parameters
-
key | the property key |
def | the default value if property is undefined |
- Returns
- the value, std::nullopt or def
The documentation for this class was generated from the following file: