Add new JSON API for better abstraction and for supporting strict JSON parsing

This commit is contained in:
Alexander Arlt
2018-02-20 21:58:26 +01:00
committed by Alex Beregszaszi
parent dcc4083b23
commit 0f29ac4e56
15 changed files with 337 additions and 53 deletions
+19 -12
View File
@@ -24,21 +24,28 @@
#include <json/json.h>
namespace dev
{
#include <string>
namespace dev {
/// Serialise the JSON object (@a _input) with indentation
inline std::string jsonPrettyPrint(Json::Value const& _input)
{
return Json::StyledWriter().write(_input);
}
std::string jsonPrettyPrint(Json::Value const& _input);
/// Serialise the JSON object (@a _input) without indentation
inline std::string jsonCompactPrint(Json::Value const& _input)
{
Json::FastWriter writer;
writer.omitEndingLineFeed();
return writer.write(_input);
}
std::string jsonCompactPrint(Json::Value const& _input);
/// Parse a JSON string (@a _input) with enabled strict-mode and writes resulting JSON object to (@a _json)
/// \param _input JSON input string
/// \param _json [out] resulting JSON object
/// \param _errs [out] Formatted error messages
/// \return \c true if the document was successfully parsed, \c false if an error occurred.
bool jsonParseStrict(std::string const& _input, Json::Value& _json, std::string* _errs = nullptr);
/// Parse a JSON string (@a _input) and writes resulting JSON object to (@a _json)
/// \param _input JSON input string
/// \param _json [out] resulting JSON object
/// \param _errs [out] Formatted error messages
/// \return \c true if the document was successfully parsed, \c false if an error occurred.
bool jsonParse(std::string const& _input, Json::Value& _json, std::string* _errs = nullptr);
}