18 static_assert(jsoncons::version().minor >= 167,
"A higher version of jsoncons is required!");
20 using json = jsoncons::json;
21 using value_type = json;
25 using value_type = key_value_type;
26 using mapped_type = key_value_type::value_type;
27 using size_type = size_t;
31 explicit object_type(
const json::object& o) : json::object(o) {}
33 explicit object_type(json::object&& o) : json::object(o) {}
39 mapped_type& operator[](
const key_type& key) {
41 return try_emplace(key).first->value();
45 const mapped_type& at(
const key_type& key)
const {
46 auto target = find(key);
47 if (target != end())
return target->value();
49 throw std::out_of_range(
"invalid key");
53 size_type count(
const key_type& key)
const {
55 bool operator()(
const value_type& val,
const key_type& key)
const {
return val.key() < key; }
56 bool operator()(
const key_type& key,
const value_type& val)
const {
return key < val.key(); }
60 if (std::binary_search(this->begin(), this->end(), key, compare{}))
return 1;
64 using array_type = json::array;
65 using string_type = std::string;
66 using number_type = double;
67 using integer_type = int64_t;
68 using boolean_type = bool;
73 if (val.type() == jsoncons::json_type::bool_value)
return type::boolean;
74 if (val.type() == jsoncons::json_type::int64_value)
return type::integer;
75 if (val.type() == jsoncons::json_type::uint64_value)
return type::integer;
76 if (val.type() == jsoncons::json_type::half_value)
return type::number;
77 if (val.type() == jsoncons::json_type::double_value)
return type::number;
78 if (val.type() == jsoncons::json_type::string_value)
return type::string;
79 if (val.type() == jsoncons::json_type::array_value)
return type::array;
80 if (val.type() == jsoncons::json_type::object_value)
return type::object;
82 throw std::logic_error(
"invalid type");
85 static object_type as_object(
const json& val) {
86 if (val.type() != jsoncons::json_type::object_value)
throw std::bad_cast();
87 return object_type(val.object_value());
90 static array_type as_array(
const json& val) {
91 if (val.type() != jsoncons::json_type::array_value)
throw std::bad_cast();
92 return val.array_value();
95 static string_type as_string(
const json& val) {
96 if (val.type() != jsoncons::json_type::string_value)
throw std::bad_cast();
97 return val.as_string();
100 static number_type as_number(
const json& val) {
101 if (get_type(val) != jwt::json::type::number)
throw std::bad_cast();
102 return val.as_double();
105 static integer_type as_integer(
const json& val) {
106 if (get_type(val) != jwt::json::type::integer)
throw std::bad_cast();
107 return val.as<integer_type>();
110 static boolean_type as_boolean(
const json& val) {
111 if (val.type() != jsoncons::json_type::bool_value)
throw std::bad_cast();
112 return val.as_bool();
115 static bool parse(json& val,
const std::string& str) {
116 val = json::parse(str);
120 static std::string serialize(
const json& val) {
121 std::ostringstream os;
122 os << jsoncons::print(val);