google protocol buffers vs json vs XML

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14028293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 18:40:43  来源:igfitidea点击:

google protocol buffers vs json vs XML

xmljsonprotocol-buffersdata-serialization

提问by Manoj Kathiriya

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

我想知道优缺点

  • Google Protocol Buffers
  • JSON
  • XML
  • 谷歌协议缓冲区
  • 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.

我想为两个应用程序实现一个通用框架,一个是 Perl,另一个是 Java。所以,想创建可以被两种技术即 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.

请与我分享您对此的宝贵想法和建议。我在 google 上看到了很多链接,但都有不同的意见。

回答by Marc Gravell

Json

杰森

  • human readable/editable
  • can be parsed without knowing schema in advance
  • excellent browser support
  • less verbose than XML
  • 人类可读/可编辑
  • 可以在不知道架构的情况下进行解析
  • 出色的浏览器支持
  • 比 XML 更简洁

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
  • 人类可读/可编辑
  • 可以在不知道架构的情况下进行解析
  • SOAP 等标准
  • 良好的工具支持(xsd、xslt、sax、dom 等)
  • 相当冗长

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.

就我个人而言,这些天我很少使用 XML。如果消费者是浏览器或公共 API,我倾向于使用 json。对于内部 API,我倾向于使用 protobuf 来提高性能。在公共 API 上提供(通过标头或单独的端点)也很有效。