json: add non-throwing overload for to_json_value

It will be needed later to avoid unnecessary try-catch blocks.
This commit is contained in:
Piotr Sarna
2019-03-19 15:47:36 +01:00
parent b46ab76d4b
commit 25264d61ee

11
json.hh
View File

@@ -82,6 +82,17 @@ inline Json::Value to_json_value(const sstring& raw) {
return root;
}
inline bool to_json_value(const sstring& raw, Json::Value& root) {
#if defined(JSONCPP_VERSION_HEXA) && (JSONCPP_VERSION_HEXA >= 0x010400) // >= 1.4.0
Json::CharReaderBuilder rbuilder;
std::unique_ptr<Json::CharReader> reader(rbuilder.newCharReader());
return reader->parse(raw.begin(), raw.end(), &root, NULL);
#else
Json::Reader reader;
return reader.parse(std::string{raw}, root);
#endif
}
template<typename Map>
inline Map to_map(const sstring& raw, Map&& map) {
Json::Value root = to_json_value(raw);