"hello": "world"


message HelloWorld {
required string name = 1;

Why do we say that protobuf uses binary format during network exchange and json don't, even though network always will transfer using binary data format?

  • 3
    The question in your title is different than your question in the post. The JSON example you provided is the message, while the Protobuf example is the schema. You define the schema in a text file, but that doesn't mean the Protobuf message will be sent as text. Can you clarify your question? – Vincent Savard Apr 3 at 13:21
  • Thanks @VincentSavard I was aware that I am putting schema, but I thought data would also be textual for protobuf (wrongly assumed, apologies). I was following logic of xml xsd as both are in text. – pzk Apr 3 at 13:33

This would be more clear if you were comparing two more similar pieces of data with non-text data components.

For example, the following JSON is ALL text:

    "NumberOfClients": 20

The 20 is two separate characters in JSON, but would be represented as an actual binary integer in Protobuf, which in this case would be a single byte: ‭00010100‬

Further, I am not sure you are properly understanding Protobuf as you are comparing apples and oranges in your question. You are comparing JSON Data to a Protobuf Schema

  • 1
    Ok, understood. Thanks for explanation. Though I knew I was putting schema in case of in case of protobuf, I wrongly assumed (apologies) that data would also be same. – pzk Apr 3 at 13:31
  • Sounds very much to the all XMLBeans in Java. – Laiv Apr 3 at 20:36
  • 1
    The last paragraph of the answer seems to be the actual answer to the question - that 20 isn't "20" but 00010100 in the protobuf says more about JSON than about protobuf. I feel this answer would be better of that last line where made the main point. – Jory Geerts Apr 4 at 14:21
  • @JoryGeerts noted, remedy attempted – TheCatWhisperer Apr 4 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.