20 static_assert(jsoncons::version().major > 0);
22 using json = jsoncons::json;
23 using value_type = json;
26 using key_type = json::key_type;
27 using mapped_type = json;
28 using value_type = std::pair<const key_type, mapped_type>;
29 using size_type = size_t;
30 using iterator = json::object_iterator;
31 using const_iterator = json::const_object_iterator;
45 json_ = std::move(o.json_);
50 mapped_type& operator[](
const key_type& key) {
return json_[key]; }
53 const mapped_type& at(
const key_type& key)
const {
return json_.at(key); }
56 size_type count(
const key_type& key)
const {
return json_.count(key); }
58 iterator begin() {
return json_.object_range().begin(); }
59 iterator end() {
return json_.object_range().end(); }
60 const_iterator begin()
const {
return json_.object_range().cbegin(); }
61 const_iterator end()
const {
return json_.object_range().cend(); }
62 const_iterator cbegin()
const {
return json_.object_range().cbegin(); }
63 const_iterator cend()
const {
return json_.object_range().cend(); }
70 using value_type = json;
71 using size_type = size_t;
72 using iterator = json::array_iterator;
73 using const_iterator = json::const_array_iterator;
77 explicit array_type(
const json& j) : json_(j) {}
79 template<
typename Iterator>
81 json_ = json::array();
82 for (
auto it = first; it != last; ++it) {
94 json_ = std::move(o.json_);
98 value_type& operator[](size_type index) {
return json_[index]; }
100 const value_type& at(size_type index)
const {
return json_.at(index); }
102 value_type
const& front()
const {
return json_.at(0); }
104 void push_back(
const value_type& val) { json_.push_back(val); }
106 iterator begin() {
return json_.array_range().begin(); }
107 iterator end() {
return json_.array_range().end(); }
108 const_iterator begin()
const {
return json_.array_range().cbegin(); }
109 const_iterator end()
const {
return json_.array_range().cend(); }
110 const_iterator cbegin()
const {
return json_.array_range().cbegin(); }
111 const_iterator cend()
const {
return json_.array_range().cend(); }
117 using string_type = std::string;
118 using number_type = double;
119 using integer_type = int64_t;
120 using boolean_type = bool;
125 if (val.type() == jsoncons::json_type::bool_value)
return type::boolean;
126 if (val.type() == jsoncons::json_type::int64_value)
return type::integer;
127 if (val.type() == jsoncons::json_type::uint64_value)
return type::integer;
128 if (val.type() == jsoncons::json_type::half_value)
return type::number;
129 if (val.type() == jsoncons::json_type::double_value)
return type::number;
130 if (val.type() == jsoncons::json_type::string_value)
return type::string;
131 if (val.type() == jsoncons::json_type::array_value)
return type::array;
132 if (val.type() == jsoncons::json_type::object_value)
return type::object;
134 throw std::logic_error(
"invalid type");
137 static object_type as_object(
const json& val) {
138 if (val.type() != jsoncons::json_type::object_value)
throw std::bad_cast();
139 return object_type(val);
142 static array_type as_array(
const json& val) {
143 if (val.type() != jsoncons::json_type::array_value)
throw std::bad_cast();
144 return array_type(val);
147 static string_type as_string(
const json& val) {
148 if (val.type() != jsoncons::json_type::string_value)
throw std::bad_cast();
149 return val.as_string();
152 static number_type as_number(
const json& val) {
153 if (get_type(val) != jwt::json::type::number)
throw std::bad_cast();
154 return val.as_double();
157 static integer_type as_integer(
const json& val) {
158 if (get_type(val) != jwt::json::type::integer)
throw std::bad_cast();
159 return val.as<integer_type>();
162 static boolean_type as_boolean(
const json& val) {
163 if (val.type() != jsoncons::json_type::bool_value)
throw std::bad_cast();
164 return val.as_bool();
167 static bool parse(json& val,
const std::string& str) {
168 val = json::parse(str);
172 static std::string serialize(
const json& val) {
173 std::ostringstream os;
174 os << jsoncons::print(val);