1

JSON

{
"hello": "world"
}

Protobuf

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?

pzk
  • 29
  • 4
  • 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 03 '19 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 03 '19 at 13:33

1 Answers1

11

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

TheCatWhisperer
  • 5,231
  • 1
  • 22
  • 41
  • 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 03 '19 at 13:31
  • Sounds very much to the all XMLBeans in Java. – Laiv Apr 03 '19 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 04 '19 at 14:21
  • @JoryGeerts noted, remedy attempted – TheCatWhisperer Apr 04 '19 at 16:08