1 #include <mbgl/style/conversion/get_json_type.hpp> 2 #include <mbgl/util/feature.hpp> 3 4 namespace mbgl { 5 namespace style { 6 namespace conversion { 7 getJSONType(const Convertible & value)8std::string getJSONType(const Convertible& value) { 9 if (isUndefined(value)) { 10 return "null"; 11 } 12 if (isArray(value)) { 13 return "array"; 14 } 15 if (isObject(value)) { 16 return "object"; 17 } 18 optional<mbgl::Value> v = toValue(value); 19 20 // Since we've already checked the non-atomic types above, value must then 21 // be a string, number, or boolean -- thus, assume that the toValue() 22 // conversion succeeds. 23 assert(v); 24 25 return v->match( 26 [&] (const std::string&) { return "string"; }, 27 [&] (bool) { return "boolean"; }, 28 [&] (auto) { return "number"; } 29 ); 30 } 31 32 } // namespace conversion 33 } // namespace style 34 } // namespace mbgl 35