21 using value_type = picojson::value;
22 using object_type = picojson::object;
23 using array_type = picojson::array;
24 using string_type = std::string;
25 using number_type = double;
26 using integer_type = int64_t;
27 using boolean_type = bool;
29 static json::type get_type(
const picojson::value& val) {
31 if (val.is<
bool>())
return type::boolean;
32 if (val.is<int64_t>())
return type::integer;
33 if (val.is<
double>())
return type::number;
34 if (val.is<std::string>())
return type::string;
35 if (val.is<picojson::array>())
return type::array;
36 if (val.is<picojson::object>())
return type::object;
38 throw std::logic_error(
"invalid type");
41 static picojson::object as_object(
const picojson::value& val) {
42 if (!val.is<picojson::object>())
throw std::bad_cast();
43 return val.get<picojson::object>();
46 static std::string as_string(
const picojson::value& val) {
47 if (!val.is<std::string>())
throw std::bad_cast();
48 return val.get<std::string>();
51 static picojson::array as_array(
const picojson::value& val) {
52 if (!val.is<picojson::array>())
throw std::bad_cast();
53 return val.get<picojson::array>();
56 static int64_t as_integer(
const picojson::value& val) {
57 if (!val.is<int64_t>())
throw std::bad_cast();
58 return val.get<int64_t>();
61 static bool as_boolean(
const picojson::value& val) {
62 if (!val.is<
bool>())
throw std::bad_cast();
63 return val.get<
bool>();
66 static double as_number(
const picojson::value& val) {
67 if (!val.is<
double>())
throw std::bad_cast();
68 return val.get<
double>();
71 static bool parse(picojson::value& val,
const std::string& str) {
72 return picojson::parse(val, str).empty();
75 static std::string serialize(
const picojson::value& val) {
return val.serialize(); }