1#ifndef JWT_CPP_NLOHMANN_JSON_TRAITS_H
2#define JWT_CPP_NLOHMANN_JSON_TRAITS_H
14 using json = nlohmann::json;
24 using jwt::json::type;
26 if (val.type() == json::value_t::boolean)
return type::boolean;
28 if (val.type() == json::value_t::number_integer)
return type::integer;
29 if (val.type() == json::value_t::number_unsigned)
return type::integer;
30 if (val.type() == json::value_t::number_float)
return type::number;
31 if (val.type() == json::value_t::string)
return type::string;
32 if (val.type() == json::value_t::array)
return type::array;
33 if (val.type() == json::value_t::object)
return type::object;
35 throw std::logic_error(
"invalid type");
39 if (val.type() != json::value_t::object)
throw std::bad_cast();
40 return val.get<json::object_t>();
44 if (val.type() != json::value_t::string)
throw std::bad_cast();
45 return val.get<std::string>();
49 if (val.type() != json::value_t::array)
throw std::bad_cast();
50 return val.get<json::array_t>();
55 case json::value_t::number_integer:
56 case json::value_t::number_unsigned:
return val.get<int64_t>();
57 default:
throw std::bad_cast();
62 if (val.type() != json::value_t::boolean)
throw std::bad_cast();
63 return val.get<
bool>();
67 if (val.type() != json::value_t::number_float)
throw std::bad_cast();
68 return val.get<
double>();
72 val = json::parse(str.begin(), str.end());
basic_claim's JSON trait implementation for Modern C++ JSON
json::boolean_t boolean_type
static bool parse(json &val, std::string str)
json::number_float_t number_type
static std::string as_string(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 bool as_boolean(const json &val)
static json::array_t as_array(const json &val)
static int64_t as_integer(const json &val)
json::number_integer_t integer_type
json::object_t object_type