【Data Format】Protobuf vs JSON

Posted by 西维蜀黍 on 2021-08-16, Last Modified on 2022-12-10

JSON

JSON (JavaScript Object Notation) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (or other serializable values).

It is a common data format with a diverse range of functionality in data interchange including communication of web applications with servers.

JSON is a language-independent data format. It was derived from JavaScript, but many modern programming languages include code to generate and parse JSON-format data. JSON filenames use the extension .json.

JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

Protocol Buffers (Protobuf)

Protocol Buffers (Protobuf) is a free and open source cross-platform library used to serialize structured data.

It is useful in developing programs to communicate with each other over a network or for storing data. The method involves an interface description language that describes the structure of some data and a program that generates source code from that description for generating or parsing a stream of bytes that represents the structured data.

Comparison

Message Format

  • Protobuf
    • Protobuf is not just a message format, it also incorporates a set of rules to define and exchang messages.
  • JSON
    • JSON is simply a message format without having any schemas.
    • JSON messages are exchanged in a human-readable text format.

Serialization

  • Protobuf supports binary serialization format whereas JSON is for simple text serialization format

Schema

  • Protobuf schemas are associated with the data
  • JSON stores data in text format and doesn’t have any schema associated with it

Speed

  • Protobuf is much faster than JSON

Benchmark

Usage

  • Protobuf is mostly useful for internal services whereas JSON is mostly useful for web applications

Backward compatibility

  • Protobuf is easier

Reference