3

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?

mahonya
  • 9,247
  • 7
  • 39
  • 68
  • Not really an answer, but this will depend hugely on the tools of each. It is trivial with protobuf-net, since that is designed to work with POCO/DTO objects, which most .NET JSON serializers will happily work with. But without that you might need to map it to a JSON-friendly DTO model. – Marc Gravell Jun 09 '11 at 09:38

2 Answers2

1

pb2json is another library that can be used.

Mike Ohlsen
  • 1,900
  • 12
  • 21
1

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

Community
  • 1
  • 1
Andrés Senac
  • 841
  • 6
  • 14