summaryrefslogtreecommitdiff
path: root/src/convert_json.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/convert_json.cpp')
-rw-r--r--src/convert_json.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/convert_json.cpp b/src/convert_json.cpp
index 1343903b4..bfd7f39c4 100644
--- a/src/convert_json.cpp
+++ b/src/convert_json.cpp
@@ -46,12 +46,15 @@ Json::Value fetchJsonValue(const std::string &url,
return Json::Value();
}
Json::Value root;
- Json::Reader reader;
std::istringstream stream(fetch_result.data);
- if (!reader.parse(stream, root)) {
+ Json::CharReaderBuilder builder;
+ builder.settings_["collectComments"] = false;
+ std::string errs;
+
+ if (!Json::parseFromStream(builder, stream, &root, &errs)) {
errorstream << "URL: " << url << std::endl;
- errorstream << "Failed to parse json data " << reader.getFormattedErrorMessages();
+ errorstream << "Failed to parse json data " << errs << std::endl;
if (fetch_result.data.size() > 100) {
errorstream << "Data (" << fetch_result.data.size()
<< " bytes) printed to warningstream." << std::endl;
@@ -64,3 +67,13 @@ Json::Value fetchJsonValue(const std::string &url,
return root;
}
+
+std::string fastWriteJson(const Json::Value &value)
+{
+ std::ostringstream oss;
+ Json::StreamWriterBuilder builder;
+ builder["indentation"] = "";
+ std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
+ writer->write(value, &oss);
+ return oss.str();
+}