diff --git a/include/chaiscript/utility/json_wrap.hpp b/include/chaiscript/utility/json_wrap.hpp index 2aa81f34..05b9e404 100644 --- a/include/chaiscript/utility/json_wrap.hpp +++ b/include/chaiscript/utility/json_wrap.hpp @@ -80,7 +80,7 @@ namespace chaiscript try { const std::map m = chaiscript::boxed_cast &>(t_bv); - json::JSON obj; + json::JSON obj(json::JSON::Class::Object); for (const auto &o : m) { obj[o.first] = to_json_object(o.second); @@ -93,7 +93,7 @@ namespace chaiscript try { const std::vector v = chaiscript::boxed_cast &>(t_bv); - json::JSON obj; + json::JSON obj(json::JSON::Class::Array); for (size_t i = 0; i < v.size(); ++i) { obj[i] = to_json_object(v[i]); @@ -132,7 +132,7 @@ namespace chaiscript try { const chaiscript::dispatch::Dynamic_Object &o = boxed_cast(t_bv); - json::JSON obj; + json::JSON obj(json::JSON::Class::Object); for (const auto &attr : o.get_attrs()) { obj[attr.first] = to_json_object(attr.second); @@ -142,6 +142,8 @@ namespace chaiscript // not a dynamic object } + if (t_bv.is_null()) return json::JSON(); // a null value + throw std::runtime_error("Unknown object type to convert to JSON"); }