YAML和JSON之间有什么不同,特别是考虑到以下几点?

  • Performance (encode/decode time)
  • 内存消耗
  • 表达清晰度
  • Library availability, ease of use (I prefer C)

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

Related:

Should I use YAML or JSON to store my Perl data?

推荐答案

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.

See the official specs, in the section entitled "YAML: Relation to JSON".

总的来说,我喜欢YAML中的某些东西,但在JSON中是不可用的.

  • 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能够使用"锚定"引用YAML文件中的其他项因此,它可以像在MySQL数据库中一样处理关系信息.
  • YAML is more robust about embedding other serialization formats such as JSON or XML within a YAML file.

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.

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的库往往比较新,但我过go 没有遇到过任何问题.请参见示例Yaml-cpp.

Json相关问答推荐

需要Jolt规范将具有动态字段的输入json转换为输出json

筛选JSON数组以使用Jolt仅保留具有最新日期/时间的条目

从Json响应中为需要每个值的Post请求提取多个值

Oracle JSON 查询中的动态列列表

从包含 JSON 对象序列的文件中获取第一个 JSON 对象

使用 jq 获取所有嵌套键和值

基于JQ中另一个对象的值 Select 对象

jq :当路径可变时更新 json 内容

无法在 json --data 中使用变量

根据数据框中的其他列值将列表 json 对象插入行

如何使用 Swiftui 判断 JSON 是否缺少键值对

使用基本身份验证通过 CURL 发布 JSON

在 JSON 字符串中react i18n 换行符

JSON对象中的JavaScript递归搜索

Jackson 没有使用 @JsonProperty 覆盖 Getter

如何使用 Newtonsoft.Json 包在 C#(4.0) 中解析我的 json 字符串?

Retrofit2.0 得到 MalformedJsonException 而 json 似乎正确?

在 HTML 数据属性上添加 JSON 是不是很糟糕?

无法将空值放入 JSON 对象

NSURLRequest 中不支持的 URL