YAML 和 JSON 有什么区别?

发布于 2024-08-10 21:14:07 字数 160 浏览 10 评论 0原文

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

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

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

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

  • Performance (encode/decode time)
  • Memory consumption
  • Expression clarity
  • 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

墨洒年华 2024-08-17 21:14:07

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

请参阅标题为 “YAML:与 JSON 的关系” 的官方规范。

一般来说,我喜欢 YAML 的某些东西是 JSON 所不具备的。

  • 正如 @jdupont 指出的,YAML 在视觉上更容易查看。事实上,YAML 主页本身就是有效的 YAML,而且很容易让人阅读。
  • YAML 能够使用“锚点”引用 YAML 文件中的其他项目。因此,它可以像 MySQL 数据库中那样处理关系信息。
  • 在 YAML 文件中嵌入其他序列化格式(例如 JSON 或 XML)时,YAML 更加强大。

实际上,最后两点对于你或我所做的事情可能都不重要,但从长远来看,我认为 YAML 将是一种更强大、更可行的数据序列化格式。

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

您将找到 JSON 和 YAML 的 C 库。 YAML 的库往往较新,但我过去使用它们没有遇到任何问题。请参阅 Yaml-cpp 示例。

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".

In general, there are certain things I like about YAML that are not available in 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 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.

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.

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.

陈甜 2024-08-17 21:14:07

差异:

  1. YAML(取决于您如何使用它)比 JSON 更具可读性
  2. JSON 通常 更快,并且可能仍然可以与更多系统互操作
  3. 可以非常快速地编写一个“足够好”的 JSON 解析器
  4. 重复的键,它们是 < em>可能有效的 JSON,肯定无效的 YAML。
  5. YAML 具有大量功能,包括注释和关系锚点。因此,YAML 语法相当复杂,并且可能难以理解。
  6. 可以在yaml中编写递归结构:{a: &b [*b]},这在某些转换器中会无限循环。即使使用循环检测,“yaml 炸弹”仍然是可能的(请参阅 xml 炸弹)。
  7. 因为没有引用,所以不可能用 JSON 中的对象引用序列化复杂的结构。因此,YAML 序列化可以更加高效。
  8. 在某些编码环境中,使用 YAML 可以允许攻击者执行任意代码

观察结果:

  1. Python 程序员通常是 YAML 的忠实粉丝,因为使用缩进而不是括号语法来指示级别。
  2. 许多程序员认为将“意义”附加到缩进上是一个糟糕的选择。
  3. 如果数据格式将离开应用程序环境、在 UI 中解析或在消息传递层中发送,则 JSON 可能是更好的选择。
  4. YAML 可以直接用于语法定义等复杂任务,并且通常是比发明新语言更好的选择。

Differences:

  1. YAML, depending on how you use it, can be more readable than JSON
  2. JSON is often faster and is probably still interoperable with more systems
  3. It's possible to write a "good enough" JSON parser very quickly
  4. Duplicate keys, which are potentially valid JSON, are definitely invalid YAML.
  5. YAML has a ton of features, including comments and relational anchors. YAML syntax is accordingly quite complex, and can be hard to understand.
  6. It is possible to write recursive structures in yaml: {a: &b [*b]}, which will loop infinitely in some converters. Even with circular detection, a "yaml bomb" is still possible (see xml bomb).
  7. Because there are no references, it is impossible to serialize complex structures with object references in JSON. YAML serialization can therefore be more efficient.
  8. In some coding environments, the use of YAML can allow an attacker to execute arbitrary code.

Observations:

  1. Python programmers are generally big fans of YAML, because of the use of indentation, rather than bracketed syntax, to indicate levels.
  2. Many programmers consider the attachment of "meaning" to indentation a poor choice.
  3. If the data format will be leaving an application's environment, parsed within a UI, or sent in a messaging layer, JSON might be a better choice.
  4. YAML can be used, directly, for complex tasks like grammar definitions, and is often a better choice than inventing a new language.
叶落知秋 2024-08-17 21:14:07

绕过深奥的理论

这回答了标题,而不是细节,因为大多数人只是像我一样从谷歌搜索结果中阅读标题,所以我觉得有必要从网络开发人员的角度解释

  1. YAML 使用空格缩进,这是 Python 开发人员熟悉的领域。
  2. JavaScript 开发人员喜欢 JSON,因为它是 JavaScript 的子集,可以在 JavaScript 中直接解释和编写,并且可以使用简写方式声明 JSON,在使用不带空格的典型变量名称时,不需要在键中使用双引号。
  3. 有大量的解析器在所有语言中都可以很好地工作,无论是 YAML 还是 JSON。
  4. 在许多情况下,YAML 的空间格式更容易查看,因为格式需要更易于人类阅读的方法。
  5. YAML 的形式虽然更紧凑且更易于查看,但如果您的编辑器中没有可见的空格格式,则手动编辑可能会非常困难。制表符不是空格,因此如果您没有编辑器将击键解释为空格,则会进一步造成混乱。
  6. JSON 的序列化和反序列化速度要快得多,因为要检查的功能比 YAML 少得多,这使得能够使用更小、更轻的代码来处理 JSON。
  7. 一个常见的误解是 YAML 需要更少的标点符号并且比 JSON 更紧凑,但这是完全错误的。空格是不可见的,因此看起来字符较少,但是如果您计算 YAML 正确解释所需的实际空格以及正确的缩进,您会发现 YAML 实际上比 JSON 需要更多的字符。 JSON 不使用空格来表示层次结构或分组,并且可以轻松地扁平化,删除不必要的空格以实现更紧凑的传输。

房间里的大象:互联网本身

JavaScript 显然以巨大的优势在 Web 上占据主导地位,并且 JavaScript 开发人员更喜欢使用 JSON 作为压倒性的数据格式以及流行的 Web API,因此在进行 Web 编程时,很难争论使用 YAML 而不是 JSON。一般意义上,因为在团队环境中您可能会被否决。事实上,大多数 Web 程序员甚至不知道 YAML 的存在,更不用说考虑使用它了。

如果您正在进行任何 Web 编程,JSON 是默认方式,因为使用 JavaScript 时不需要翻译步骤,因此在这种情况下您必须提出更好的参数来使用 YAML 而不是 JSON。

Bypassing esoteric theory

This answers the title, not the details as most just read the title from a search result on google like me so I felt it was necessary to explain from a web developer perspective.

  1. YAML uses space indentation, which is familiar territory for Python developers.
  2. JavaScript developers love JSON because it is a subset of JavaScript and can be directly interpreted and written inside JavaScript, along with using a shorthand way to declare JSON, requiring no double quotes in keys when using typical variable names without spaces.
  3. There are a plethora of parsers that work very well in all languages for both YAML and JSON.
  4. YAML's space format can be much easier to look at in many cases because the formatting requires a more human-readable approach.
  5. YAML's form while being more compact and easier to look at can be deceptively difficult to hand edit if you don't have space formatting visible in your editor. Tabs are not spaces so that further confuses if you don't have an editor to interpret your keystrokes into spaces.
  6. JSON is much faster to serialize and deserialize because of significantly less features than YAML to check for, which enables smaller and lighter code to process JSON.
  7. A common misconception is that YAML needs less punctuation and is more compact than JSON but this is completely false. Whitespace is invisible so it seems like there are less characters, but if you count the actual whitespace which is necessary to be there for YAML to be interpreted properly along with proper indentation, you will find YAML actually requires more characters than JSON. JSON doesn't use whitespace to represent hierarchy or grouping and can be easily flattened with unnecessary whitespace removed for more compact transport.

The Elephant in the room: The Internet itself

JavaScript so clearly dominates the web by a huge margin and JavaScript developers prefer using JSON as the data format overwhelmingly along with popular web APIs so it becomes difficult to argue using YAML over JSON when doing web programming in the general sense as you will likely be outvoted in a team environment. In fact, the majority of web programmers aren't even aware YAML exists, let alone consider using it.

If you are doing any web programming, JSON is the default way to go because no translation step is needed when working with JavaScript so then you must come up with a better argument to use YAML over JSON in that case.

厌味 2024-08-17 21:14:07

这个问题已经有 6 年历史了,但奇怪的是,没有一个答案真正解决了所有四个点(速度、内存、表现力、可移植性)。

速度

显然,这取决于实现,但由于 JSON 的使用如此广泛,并且很容易实现,因此它往往会获得更多的本机支持,从而提高速度。考虑到 YAML 可以完成 JSON 所做的所有事情,而且还可以做更多的事情,因此很可能在两者的任何类似实现中,JSON 会更快。

但是,鉴于 YAML 文件可能比其 JSON 对应文件稍小(由于 ", 字符较少),因此可能高度优化的 YAML 解析器在特殊情况下可能会更快。

基本上

很难理解为什么它们会比 JSON 解析器更高效。

,如果 YAML 解析器表示相同的数据结构,

那么 在其他人看来,Python 程序员更喜欢 YAML,JavaScript 程序员更喜欢 JSON,我将做出以下观察:

  • 记住 JSON 的整个语法很容易,因此对理解任何 JSON 文件的含义都非常有信心。任何人都可以理解。
  • 由于很少有解析器实现整个规范,因此更难确定给定上下文中给定表达式的含义。JSON
  • 中缺乏注释。练习,确实很痛苦。

可移植性

很难想象没有 JSON 库的现代语言。也很难想象 JSON 解析器会实现任何低于完整规范的内容。 YAML 拥有广泛的支持,但不如 JSON 普遍,并且每个解析器都实现不同的子集。因此,YAML 文件的互操作性比您想象的要差。

总结

JSON 是性能(如果相关)和互操作性方面的赢家。 YAML 更适合人工维护的文件。 HJSON 是一个不错的折衷方案,尽管可移植性大大降低。 JSON5 是一个更合理的折衷方案,具有定义良好的语法。

This question is 6 years old, but strangely, none of the answers really addresses all four points (speed, memory, expressiveness, portability).

Speed

Obviously this is implementation-dependent, but because JSON is so widely used, and so easy to implement, it has tended to receive greater native support, and hence speed. Considering that YAML does everything that JSON does, plus a truckload more, it's likely that of any comparable implementations of both, the JSON one will be quicker.

However, given that a YAML file can be slightly smaller than its JSON counterpart (due to fewer " and , characters), it's possible that a highly optimised YAML parser might be quicker in exceptional circumstances.

Memory

Basically the same argument applies. It's hard to see why a YAML parser would ever be more memory efficient than a JSON parser, if they're representing the same data structure.

Expressiveness

As noted by others, Python programmers tend towards preferring YAML, JavaScript programmers towards JSON. I'll make these observations:

  • It's easy to memorise the entire syntax of JSON, and hence be very confident about understanding the meaning of any JSON file. YAML is not truly understandable by any human. The number of subtleties and edge cases is extreme.
  • Because few parsers implement the entire spec, it's even harder to be certain about the meaning of a given expression in a given context.
  • The lack of comments in JSON is, in practice, a real pain.

Portability

It's hard to imagine a modern language without a JSON library. It's also hard to imagine a JSON parser implementing anything less than the full spec. YAML has widespread support, but is less ubiquitous than JSON, and each parser implements a different subset. Hence YAML files are less interoperable than you might think.

Summary

JSON is the winner for performance (if relevant) and interoperability. YAML is better for human-maintained files. HJSON is a decent compromise although with much reduced portability. JSON5 is a more reasonable compromise, with well-defined syntax.

生生漫 2024-08-17 21:14:07

GIT 和 YAML

其他答案都很好。首先阅读这些内容。但我会添加有时使用 YAML 的另一个原因:git

许多编程项目越来越多地使用 git 存储库进行分发和存档。而且,虽然 git 存储库的历史记录可以同等地存储 JSON 和 YAML 文件,但用于跟踪和显示文件更改的“diff”方法是面向行的。由于 YAML 被迫面向行,因此 YAML 文件中的任何微小更改都更容易被人看到。

当然,确实可以通过对字符串/键进行排序并添加缩进来“使 JSON 文件变得漂亮”。但这不是默认设置,而且我很懒。

就我个人而言,我通常使用 JSON 进行系统间交互。我经常将 YAML 用于配置文件、静态文件和跟踪文件。 (我通常也会避免添加 YAML 关系锚点。生命太短,无法寻找循环。)

此外,如果速度和空间确实是一个问题,我也不使用其中任何一个。您可能想看看 BSON。

GIT and YAML

The other answers are good. Read those first. But I'll add one other reason to use YAML sometimes: git.

Increasingly, many programming projects use git repositories for distribution and archival. And, while a git repo's history can equally store JSON and YAML files, the "diff" method used for tracking and displaying changes to a file is line-oriented. Since YAML is forced to be line-oriented, any small changes in a YAML file are easier to see by a human.

It is true, of course, that JSON files can be "made pretty" by sorting the strings/keys and adding indentation. But this is not the default and I'm lazy.

Personally, I generally use JSON for system-to-system interaction. I often use YAML for config files, static files, and tracked files. (I also generally avoid adding YAML relational anchors. Life is too short to hunt down loops.)

Also, if speed and space are really a concern, I don't use either. You might want to look at BSON.

丘比特射中我 2024-08-17 21:14:07

我发现 YAML 更容易看:更少的括号、“”等。虽然 YAML 中存在制表符的烦恼……但人们会掌握它的窍门。

就性能/资源而言,我预计两者之间不会有太大差异。

此外,我们正在讨论配置文件,因此我不会期望编码/解码活动的频率很高,不是吗?

I find YAML to be easier on the eyes: less parenthesis, "" etc. Although there is the annoyance of tabs in YAML... but one gets the hang of it.

In terms of performance/resources, I wouldn't expect big differences between the two.

Futhermore, we are talking about configuration files and so I wouldn't expect a high frequency of encode/decode activity, no?

脸赞 2024-08-17 21:14:07

从技术上讲,YAML 提供的功能远不止 JSON (YAML v1.2是 JSON 的超集):

  • 注释
  • 锚点和继承 - 3 个相同项目的示例:

    item1: &anchor_name
      名称: 测试
      标题:测试标题
    项目2:*锚点名称
    第3项:
      <<:*锚点名称
      # 你可以添加额外的东西。
    
  • ...

大多数时候人们不会使用这些额外的功能,主要区别在于 YAML 使用缩进,而 < strong>JSON 使用括号。这使得 YAML 更加简洁和可读(对于受过训练的人来说)。

选择哪一个?

  • YAML 额外的功能和简洁的符号使其成为配置文件(非用户提供的文件)的不错选择。
  • JSON 有限的功能、广泛的支持和更快的解析使其成为互操作性和用户提供数据的绝佳选择。

Technically YAML offers a lot more than JSON (YAML v1.2 is a superset of JSON):

  • comments
  • anchors and inheritance - example of 3 identical items:

    item1: &anchor_name
      name: Test
      title: Test title
    item2: *anchor_name
    item3:
      <<: *anchor_name
      # You may add extra stuff.
    
  • ...

Most of the time people will not use those extra features and the main difference is that YAML uses indentation whilst JSON uses brackets. This makes YAML more concise and readable (for the trained eye).

Which one to choose?

  • YAML extra features and concise notation makes it a good choice for configuration files (non-user provided files).
  • JSON limited features, wide support, and faster parsing makes it a great choice for interoperability and user provided data.
那一片橙海, 2024-08-17 21:14:07

如果您不需要 YAML 具有而 JSON 没有的任何功能,我会更喜欢 JSON,因为它非常简单并且得到广泛支持(有很多多种语言的库)。 YAML 更复杂并且支持较少。我认为解析速度或内存使用不会有太大不同,并且可能不是程序性能的重要组成部分。

If you don't need any features which YAML has and JSON doesn't, I would prefer JSON because it is very simple and is widely supported (has a lot of libraries in many languages). YAML is more complex and has less support. I don't think the parsing speed or memory use will be very much different, and maybe not a big part of your program's performance.

记忆で 2024-08-17 21:14:07

基准测试结果

下面是比较 YAML 与 JSON 加载时间的基准测试结果,在 Python 和 Perl 上

JSON 更快,但牺牲了一些可读性和注释等功能

测试方法

结果

Python 3.8.3 timeit
    JSON:            0.108
    YAML CLoader:    3.684
    YAML:           29.763

Perl 5.26.2 Benchmark::cmpthese
    JSON XS:         0.107
    YAML XS:         0.574
    YAML Syck:       1.050

Perl 5.26.2 Dumbbench (Brian D Foy, excludes outliers)
    JSON XS:         0.102
    YAML XS:         0.514
    YAML Syck:       1.027

Benchmark results

Below are the results of a benchmark to compare YAML vs JSON loading times, on Python and Perl

JSON is much faster, at the expense of some readability, and features such as comments

Test method

Results

Python 3.8.3 timeit
    JSON:            0.108
    YAML CLoader:    3.684
    YAML:           29.763

Perl 5.26.2 Benchmark::cmpthese
    JSON XS:         0.107
    YAML XS:         0.574
    YAML Syck:       1.050

Perl 5.26.2 Dumbbench (Brian D Foy, excludes outliers)
    JSON XS:         0.102
    YAML XS:         0.514
    YAML Syck:       1.027
夕嗳→ 2024-08-17 21:14:07

来源:Arnaud Lauret 所著的《Web API 设计》。 :

JSON 数据格式

JSON 是一种基于 JavaScript 编程语言描述数据方式的文本数据格式,但尽管其名称如此,却完全独立于语言(请参阅 https://www.json.org/)。使用 JSON,您可以描述包含无序名称/值对的对象以及包含有序值的数组或列表,如图所示。

输入图像描述这里

对象由大括号 ({}) 分隔。名称是带引号的字符串(“名称”),并通过冒号 (:) 与其值分隔。值可以是字符串(如“value”)、数字(如 1.23)、布尔值(true 或 false)、空值 null、对象或数组。数组由方括号 ([]) 分隔,其值由逗号 (,) 分隔。
JSON 格式可以使用任何编程语言轻松解析。它也相对容易阅读和编写。它被广泛应用于多种用途,例如数据库、配置文件,当然还有 API。

YAML

YAML(YAML 不是标记语言)是一种人性化的数据序列化格式。与 JSON 一样,YAML (http://yaml.org) 是一种键/值数据格式。该图显示了两者的比较。

输入图像描述这里

请注意以下几点:

  • YAML 中的属性名称和值周围没有双引号 (" ")。

  • JSON 的结构花括号 ({}) 和逗号 (,) 被换行符和
    YAML 中的缩进。

  • 数组括号 ([]) 和逗号 (,) 被破折号 (-) 和换行符替换
    YAML

  • JSON 不同,YAML 允许以井号 (#) 开头的注释。
    将其中一种格式转换为另一种格式相对容易。但请预先警告,将 YAML 文档转换为 JSON 时,您将丢失注释。

From: Arnaud Lauret Book “The Design of Web APIs.” :

The JSON data format

JSON is a text data format based on how the JavaScript programming language describes data but is, despite its name, completely language-independent (see https://www.json.org/). Using JSON, you can describe objects containing unordered name/value pairs and also arrays or lists containing ordered values, as shown in this figure.

enter image description here

An object is delimited by curly braces ({}). A name is a quoted string ("name") and is sep- arated from its value by a colon (:). A value can be a string like "value", a number like 1.23, a Boolean (true or false), the null value null, an object, or an array. An array is delimited by brackets ([]), and its values are separated by commas (,).
The JSON format is easily parsed using any programming language. It is also relatively easy to read and write. It is widely adopted for many uses such as databases, configura- tion files, and, of course, APIs.

YAML

YAML (YAML Ain’t Markup Language) is a human-friendly, data serialization format. Like JSON, YAML (http://yaml.org) is a key/value data format. The figure shows a comparison of the two.

enter image description here

Note the following points:

  • There are no double quotes (" ") around property names and values in YAML.

  • JSON’s structural curly braces ({}) and commas (,) are replaced by newlines and
    indentation in YAML.

  • Array brackets ([]) and commas (,) are replaced by dashes (-) and newlines in
    YAML.

  • Unlike JSON, YAML allows comments beginning with a hash mark (#).
    It is relatively easy to convert one of those formats into the other. Be forewarned though, you will lose comments when converting a YAML document to JSON.

天暗了我发光 2024-08-17 21:14:07

由于这个问题现在在搜索 YAML 和 JSON 时非常突出,因此值得注意两者之间一个很少被引用的区别:许可证。 JSON 声称拥有 JSON 用户必须遵守的 许可证(包括法律上不明确的“应用于善,而不是恶”)。 YAML 不包含此类许可声明,这可能是一个重要的区别(对您的律师来说,如果不是对您而言)。

Since this question now features prominently when searching for YAML and JSON, it's worth noting one rarely-cited difference between the two: license. JSON purports to have a license which JSON users must adhere to (including the legally-ambiguous "shall be used for Good, not Evil"). YAML carries no such license claim, and that might be an important difference (to your lawyer, if not to you).

野心澎湃 2024-08-17 21:14:07

有时您不必决定选择其中之一。

例如,在 Go 中,您可以同时拥有两者:

type Person struct {
    Name string `json:"name" yaml:"name"`
    Age int `json:"age" yaml:"age"`
}

Sometimes you don't have to decide for one over the other.

In Go, for example, you can have both at the same time:

type Person struct {
    Name string `json:"name" yaml:"name"`
    Age int `json:"age" yaml:"age"`
}
醉生梦死 2024-08-17 21:14:07

我发现 YAML 和 JSON 都非常有效。对我来说,真正决定何时使用一种语言而不是另一种语言的唯一两件事是,该语言最常用的用途。例如,如果我使用 Java、Javascript,我将使用 JSON。对于 Java,我将使用他们自己的对象,这些对象几乎都是 JSON,但缺乏某些功能,如果需要,我会将其转换为 JSON,或者首先将其转换为 JSON。我这样做是因为这在 Java 中很常见,并且可以让其他 Java 开发人员更轻松地修改我的代码。第二件事是我是否使用它来让程序记住属性,或者程序是否以配置文件的形式接收指令,在这种情况下我将使用 YAML,因为它很容易被人类阅读,具有良好的性能。即使您不知道 YAML 是如何工作的,它也很容易修改。然后,程序将读取它并将其转换为 JSON 或该语言首选的任何格式。

最后,老实说这并不重要。任何有经验的程序员都可以轻松阅读 JSON 和 YAML。

I find both YAML and JSON to be very effective. The only two things that really dictate when one is used over the other for me is one, what the language is used most popularly with. For example, if I'm using Java, Javascript, I'll use JSON. For Java, I'll use their own objects, which are pretty much JSON but lacking in some features, and convert it to JSON if I need to or make it in JSON in the first place. I do that because that's a common thing in Java and makes it easier for other Java developers to modify my code. The second thing is whether I'm using it for the program to remember attributes, or if the program is receiving instructions in the form of a config file, in this case I'll use YAML, because it's very easily human read, has nice looking syntax, and is very easy to modify, even if you have no idea how YAML works. Then, the program will read it and convert it to JSON, or whatever is preferred for that language.

In the end, it honestly doesn't matter. Both JSON and YAML are easily read by any experienced programmer.

橘亓 2024-08-17 21:14:07

如果您担心更好的解析速度,那么可以选择将数据存储在 JSON 中。我必须从文件会受到其他用户修改的位置解析数据,因此我使用 YAML,因为与 JSON 相比,它提供了更好的可读性。
您还可以在 YAML 文件中添加注释,这是在 JSON 文件中无法完成的。

If you are concerned about better parsing speed then storing the data in JSON is the option. I had to parse the data from a location where the file was subject to modification from other users and hence I used YAML as it provides better readability compared to JSON.
And you can also add comments in the YAML file which can't be done in a JSON file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文