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;
66 using json::array::array;
67 explicit array_type(
const json::array& a) : json::array(a) {}
68 explicit array_type(json::array&& a) : json::array(a) {}
69 value_type
const& front()
const {
return this->operator[](0U); }
71 using string_type = std::string;
72 using number_type = double;
73 using integer_type = int64_t;
74 using boolean_type = bool;
79 if (val.type() == jsoncons::json_type::bool_value)
return type::boolean;
80 if (val.type() == jsoncons::json_type::int64_value)
return type::integer;
81 if (val.type() == jsoncons::json_type::uint64_value)
return type::integer;
82 if (val.type() == jsoncons::json_type::half_value)
return type::number;
83 if (val.type() == jsoncons::json_type::double_value)
return type::number;
84 if (val.type() == jsoncons::json_type::string_value)
return type::string;
85 if (val.type() == jsoncons::json_type::array_value)
return type::array;
86 if (val.type() == jsoncons::json_type::object_value)
return type::object;
88 throw std::logic_error(
"invalid type");
91 static object_type as_object(
const json& val) {
92 if (val.type() != jsoncons::json_type::object_value)
throw std::bad_cast();
93 return object_type(val.object_value());
96 static array_type as_array(
const json& val) {
97 if (val.type() != jsoncons::json_type::array_value)
throw std::bad_cast();
98 return array_type(val.array_value());
101 static string_type as_string(
const json& val) {
102 if (val.type() != jsoncons::json_type::string_value)
throw std::bad_cast();
103 return val.as_string();
106 static number_type as_number(
const json& val) {
107 if (get_type(val) != jwt::json::type::number)
throw std::bad_cast();
108 return val.as_double();
111 static integer_type as_integer(
const json& val) {
112 if (get_type(val) != jwt::json::type::integer)
throw std::bad_cast();
113 return val.as<integer_type>();
116 static boolean_type as_boolean(
const json& val) {
117 if (val.type() != jsoncons::json_type::bool_value)
throw std::bad_cast();
118 return val.as_bool();
121 static bool parse(json& val,
const std::string& str) {
122 val = json::parse(str);
126 static std::string serialize(
const json& val) {
127 std::ostringstream os;
128 os << jsoncons::print(val);