236

I would like to know the merits & de-merits of

  • Google Protocol Buffers
  • JSON
  • XML

I want to implement one common framework for two application, one in Perl and second in Java. So, would like to create common service which can be used by both technology i.e. Perl & Java.

Both are web-applications.

Please share me your valuable thoughts & suggestion on this. I have seen many links on google but all have mixed opinions.

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
Manoj Kathiriya
  • 3,366
  • 5
  • 19
  • 19
  • 9
    And you think there's likely to be a concensus here? – Barmar Dec 25 '12 at 07:16
  • JSON vs XML : http://stackoverflow.com/questions/4862310/json-and-xml-comparison – rai.skumar Dec 25 '12 at 07:16
  • 1
    Thanks lot. But would like to know more Protocol Buffers vs JSON. – Manoj Kathiriya Dec 25 '12 at 07:24
  • 24
    @Barmar It' not about consensus, it's about rational choice, about pros and cons, it's good that the question was asked before the meta police started to lower the quality of SO content. – Boris Treukhov Nov 18 '14 at 06:40
  • I used to object strongly to such questions being closed arbitrarily. But the fact is, if I were consulting to a project that needed to make this choice, I would want a lot more information than typically appears in an SO post; any advice you will get here is anecdotal and based on almost complete ignorance of the requirements and constraints of your particular project. – Michael Kay Dec 30 '16 at 23:23
  • It's got a lot of upvotes for something that is "not constructive". – pojo-guy Feb 23 '17 at 01:00
  • the info provided is definitely better than nothing. if the answer contained false or unqualified arguable statements then perhaps it's dangerous. but it doesn't. the points made are either factual or well-evidenced or well-agreed-upon in the community. i don't understand why the question was closed as not constructive. meta police gotta go. seriously. – BaltoStar Mar 02 '17 at 04:01
  • 1
    Michael - that's what the upvotes are for. The quality of information in the post depends on the answer written, not on whether that answer appears as a StackOverflow posting. – Dan Nissenbaum Jul 23 '17 at 21:54

1 Answers1

294

Json

  • human readable/editable
  • can be parsed without knowing schema in advance
  • excellent browser support
  • less verbose than XML

XML

  • human readable/editable
  • can be parsed without knowing schema in advance
  • standard for SOAP etc
  • good tooling support (xsd, xslt, sax, dom, etc)
  • pretty verbose

Protobuf

  • very dense data (small output)
  • hard to robustly decode without knowing the schema (data format is internally ambiguous, and needs schema to clarify)
  • very fast processing
  • not intended for human eyes (dense binary)

All have good support on most platforms.

Personally, I rarely use XML these days. If the consumer is a browser or a public API I tend to use json. For internal APIs I tend to use protobuf for performance. Offering both on public API (either via headers, or separate endpoints) works well too.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • 11
    XML is more work to decode, but validation can be a major advantage over JSON. Validating your XML with a schema before you process a payment transaction it contains gives you an extra layer of robustness. – CC. Jul 11 '13 at 17:37
  • So it is hard to get comparably fast performance out of JSON to Protobuf? – IgorGanapolsky May 19 '14 at 18:54
  • 14
    XML also allows a narrative style where text is alternated with tags inclusions like `This is a narrative style. Tags could appear in the middle of text`. This is the unique feature of XML when compared with JSON and Protocol Buffers. – Paul Jun 16 '14 at 12:33
  • 3
    @Marc Gravell: How about in terms of forward-compatibility. It's my impression that this is one of protobuf's big selling points? – Thomas Ahle Jul 06 '14 at 16:47
  • @Thomas true, but there are json and xml serializers that support round-trip of unexpected data etc – Marc Gravell Jul 06 '14 at 17:22
  • 1
    Igor Ganapolsky it is my understanding that this is pretty much conceptually impossible, as there is very little to no parsing necessary for protobuffs, while the processing phase is long and inevitable with json. – Jules G.M. Sep 12 '15 at 04:57
  • 6
    Just to mention that you can use schemas with JSON too. – Jesus Angulo May 25 '17 at 20:00
  • 1
    Adding to the points made by @JesusAngulo and CC: JSON Schema can provide documentation and validation of the objects sent: http://json-schema.org/implementations.html#validators – Peter W Jul 20 '18 at 01:21