mahonya
mahonya

Reputation: 10055

Can I serialize/deserialize JSON from protocol buffers with C++?

There are frameworks for Java and other languages that help connect protocol buffers to JSON, but I have not seen a native solution in C++.

Is there a library/framework that I can use to connect C++ protocol buffer objects to JSON?

Upvotes: 3

Views: 5613

Answers (2)

Mike Ohlsen
Mike Ohlsen

Reputation: 1900

pb2json is another library that can be used.

Upvotes: 1

Andrés Senac
Andrés Senac

Reputation: 851

I'm developing one. I'm using the protobuf's reflection mechanism to parse any generated protobuf. Here http://corbasim.googlecode.com/svn/trunk/protobuf2json_exported.zip you can find an initial implementation of this idea. It currently just parse string fields, but I want to support any type as soon as possible.

For a message Foo:

message Foo {
   optional string text = 1;
}

it can parse instances of Foo by this way:

Foo foo;

const std::string json_foo = "{\"text\": \"Hello world\"}";

protobuf2json::json::parse(foo, json_foo)

By the same way, I want to write a JSON serializer from protobuf generated types.

There is a similar question here:

C++ Protobuf to/from JSON conversion

Upvotes: 1

Related Questions