1#ifndef JWT_CPP_NLOHMANN_JSON_TRAITS_H
2#define JWT_CPP_NLOHMANN_JSON_TRAITS_H
13 using json = nlohmann::json;
24 using jwt::json::type;
26 if (val.type() == json::value_t::boolean)
29 if (val.type() == json::value_t::number_integer)
31 if (val.type() == json::value_t::number_unsigned)
33 if (val.type() == json::value_t::number_float)
35 if (val.type() == json::value_t::string)
37 if (val.type() == json::value_t::array)
39 if (val.type() == json::value_t::object)
42 throw std::logic_error(
"invalid type");
47 if (val.type() != json::value_t::object)
48 throw std::bad_cast();
49 return val.get<json::object_t>();
54 if (val.type() != json::value_t::string)
55 throw std::bad_cast();
56 return val.get<std::string>();
61 if (val.type() != json::value_t::array)
62 throw std::bad_cast();
63 return val.get<json::array_t>();
70 case json::value_t::number_integer:
71 case json::value_t::number_unsigned:
return val.get<int64_t>();
72 default:
throw std::bad_cast();
78 if (val.type() != json::value_t::boolean)
79 throw std::bad_cast();
80 return val.get<
bool>();
85 if (val.type() != json::value_t::number_float)
86 throw std::bad_cast();
87 return val.get<
double>();
92 val = json::parse(str.begin(), str.end());
json::boolean_t boolean_type
static int64_t as_int(const json &val)
static bool parse(json &val, std::string str)
json::number_float_t number_type
static std::string as_string(const json &val)
static bool as_bool(const json &val)
static json::object_t as_object(const json &val)
static std::string serialize(const json &val)
static jwt::json::type get_type(const json &val)
static double as_number(const json &val)
static json::array_t as_array(const json &val)
json::number_integer_t integer_type
json::object_t object_type