0

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 :-

  1. The Json being sent by server need to be modified and many cases.
  2. 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 ?

CMouse
  • 130
  • 3
  • 19
  • What do you mean by "the JSON needs to be modified" is the server sending invalid JSON ? – Drax Mar 15 '17 at 09:53
  • No, I need to manipulate the json returned by server and then resend it for some other operations – CMouse Mar 16 '17 at 12:03

0 Answers0