Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard mapping between JSON and Protocol Buffers?

From a comment on the announcement blog post:

Regarding JSON: JSON is structured similarly to Protocol Buffers, but protocol buffer binary format is still smaller and faster to encode. JSON makes a great text encoding for protocol buffers, though -- it's trivial to write an encoder/decoder that converts arbitrary protocol messages to and from JSON, using protobuf reflection. This is a good way to communicate with AJAX apps, since making the user download a full protobuf decoder when they visit your page might be too much.

It may be trivial to cook up a mapping, but is there a single "obvious" mapping between the two that any two separate dev teams would naturally settle on? If two products supported PB data and could interoperate because they shared the same .proto spec, I wonder if they would still be able to interoperate if they independently introduced a JSON reflection of the same spec. There might be some arbitrary decisions to be made, e.g. should enum values be represented by a string (to be human-readable a la typical JSON) or by their integer value?

So is there an established mapping, and any open source implementations for generating JSON encoder/decoders from .proto specs?

like image 518
Daniel Earwicker Avatar asked Mar 30 '10 11:03

Daniel Earwicker


People also ask

Does protobuf support JSON?

Utility classes to convert protobuf messages to/from JSON format. The JSON format follows Proto3 JSON specification and only proto3 features are supported.

How is protobuf different from JSON?

JSON is standardized and is supported by almost all languages. Protobuf vs JSON Both are for serialization; however, the key difference is that Protobuf is binary data –interchange format, whereas JSON stores data in human-readable text format.

Is protobuf better than JSON?

JSON is usually easier to debug (the serialized format is human-readable), and easier to work with (no need to define message types, compile them, install additional libraries etc). Protobuf on the other hand usually compresses data better and has built-in protocol documentation via the schema.

Are Protocol buffers still used?

In particular, it was designed to be smaller and faster than XML. Protocol Buffers are widely used at Google for storing and interchanging all kinds of structured information. The method serves as a basis for a custom remote procedure call (RPC) system that is used for nearly all inter-machine communication at Google.


1 Answers

May be this is helpful http://code.google.com/p/protobuf-java-format/

like image 71
Aravind Yarram Avatar answered Sep 19 '22 18:09

Aravind Yarram