YAML 和 JSON 有什么区别? [英] What is the difference between YAML and JSON?

查看:32
本文介绍了YAML 和 JSON 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

YAML 和 JSON 有什么区别,具体考虑以下几点?

What are the differences between YAML and JSON, specifically considering the following things?

  • 性能(编码/解码时间)
  • 内存消耗
  • 表达清晰
  • 图书馆的可用性、易用性(我更喜欢 C)

我计划在我们的嵌入式系统中使用这两个中的一个来存储配置文件.

I was planning to use one of these two in our embedded system to store configure files.

我应该使用 YAML 还是 JSON 来存储我的 Perl 数据?

推荐答案

从技术上讲,YAML 是 JSON 的超集.这意味着,至少在理论上,YAML 解析器可以理解 JSON,但反过来不一定.

Technically YAML is a superset of JSON. This means that, in theory at least, a YAML parser can understand JSON, but not necessarily the other way around.

请参阅标题为 "YAML:与 JSON 的关系".

总的来说,我喜欢 YAML 的某些方面,但 JSON 中没有.

In general, there are certain things I like about YAML that are not available in JSON.

  • 正如@jdupont 指出的,YAML 在视觉上更易于查看.事实上,YAML 主页 本身就是有效的 YAML,但它很容易被人类阅读.
  • YAML 能够使用锚点"引用 YAML 文件中的其他项目.因此,它可以像在 MySQL 数据库中找到的那样处理关系信息.
  • YAML 在将其他序列化格式(例如 JSON 或 XML) 嵌入到 YAML 文件中方面更加强大.
  • As @jdupont pointed out, YAML is visually easier to look at. In fact the YAML homepage is itself valid YAML, yet it is easy for a human to read.
  • YAML has the ability to reference other items within a YAML file using "anchors." Thus it can handle relational information as one might find in a MySQL database.
  • YAML is more robust about embedding other serialization formats such as JSON or XML within a YAML file.

在实践中,最后两点都不会对你我所做的事情产生影响,但从长远来看,我认为 YAML 将是一种更健壮和可行的数据序列化格式.

In practice neither of these last two points will likely matter for things that you or I do, but in the long term, I think YAML will be a more robust and viable data serialization format.

目前,AJAX 和其他 Web 技术倾向于使用 JSON.YAML 目前更多地用于离线数据处理.例如,它默认包含在基于 C 的 OpenCV 计算机视觉包中,而 JSON 则不包含.

Right now, AJAX and other web technologies tend to use JSON. YAML is currently being used more for offline data processes. For example, it is included by default in the C-based OpenCV computer vision package, whereas JSON is not.

您会发现 JSON 和 YAML 的 C 库.YAML 的库往往更新,但我过去没有遇到过它们的问题.参见例如 Yaml-cpp.

You will find C libraries for both JSON and YAML. YAML's libraries tend to be newer, but I have had no trouble with them in the past. See for example Yaml-cpp.

这篇关于YAML 和 JSON 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆