summaryrefslogtreecommitdiff
path: root/src/mbgl/style/conversion/json.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/style/conversion/json.hpp')
-rw-r--r--src/mbgl/style/conversion/json.hpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/mbgl/style/conversion/json.hpp b/src/mbgl/style/conversion/json.hpp
new file mode 100644
index 0000000000..0817ac09df
--- /dev/null
+++ b/src/mbgl/style/conversion/json.hpp
@@ -0,0 +1,28 @@
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/style/rapidjson_conversion.hpp>
+
+#include <string>
+#include <sstream>
+
+namespace mbgl {
+namespace style {
+namespace conversion {
+
+template <class T, class...Args>
+optional<T> convertJSON(const std::string& json, Error& error, Args&&...args) {
+ JSDocument document;
+ document.Parse<0>(json.c_str());
+
+ if (document.HasParseError()) {
+ std::stringstream message;
+ message << document.GetErrorOffset() << " - " << rapidjson::GetParseError_En(document.GetParseError());
+ error = { message.str() };
+ return {};
+ }
+
+ return convert<T, JSValue>(document, error, std::forward<Args>(args)...);
+}
+
+} // namespace conversion
+} // namespace style
+} // namespace mbgl