I am developing a C++ client and they have used protobufs to convert JSON (that client send) to Protobuf and send response back again in JSON format.
The thing is I need a powerful json parser and I feel Google protocol buffers are the best. Till now i have used Boost Json Parser (P-Tree) and tried Rapid Json but they are not so flexible.
Use Case :-
- The Json being sent by server need to be modified and many cases.
- Client will create JSON internally using a wrapper of protobuf and send it to server.
I load Json in following way, from User
try
{
std::ifstream fileHandle(sJsonFile.c_str());
if (!fileHandle.is_open())
{
ErrorHandler::getErrorInstance().setError(ERR_JSON_FILE_OPEN, sJsonFile);
return EXIT_FAILURE;
}
boost::property_tree::read_json(fileHandle, root);
fileHandle.close();
}
catch (boost::property_tree::json_parser::json_parser_error& err)
{
ErrorHandler::getErrorInstance().setError(ERR_ILLFORMED_JSON, err.what());
return EXIT_FAILURE;
}
Or from Response JSON like this
try
{
std::stringstream ss;
ss << sJsonResponse;
boost::property_tree::read_json(ss, root);
}
catch (boost::property_tree::json_parser::json_parser_error& err)
{
ErrorHandler::getErrorInstance().setError(ERR_ILLFORMED_JSON, err.what());
return EXIT_FAILURE;
}
The problem lies in JSON modification as the server sends the jsons that may or maynot be in a same common format so the modification of particular key is difficult to parse and modify.
How can I use protobufs to overcome this ?