YAML:它是一种轻量级、人类可读的数据表示语言。它主要旨在使格式易于阅读,同时包含复杂的功能。由于 YAML 是 JSON 的超集,因此它可以使用 YAML 解析器来解析 JSON。YAML 中的扩展名是.yaml或.yml 。 YAML 规范允许用户定义数据类型以及显式数据类型。
YAML 中最常用的数据类型是:
- 数字
- 字符串
- 空值
- 布尔值
- 日期和时间戳
- 序列
- 嵌套值
例子:
Origin:
author: Dan Brown
language: English
publication-date: 2017-10-03
pages: 461
description: | When billionaire researcher Edmond Kirsch is killed,
it is up to Robert Langdon & Ambra Vidal to honor
his memory by making public his findings concerning the
origin of human life and its destiny.
JSON:它是一种独立于语言的人类可读语言,因其简单性而最常用于基于 Web 的应用程序中。JSON 扩展名以.json结尾。 JSON 是 XML 的用户友好替代品,因为它重量轻且易于阅读。
JSON 中使用的一些有效数据类型是:
- 数字
- 字符串
- 对象
- 数组
例子:
{
"Origin": {
"author": "Dan Brown",
"language": "English",
"publication-date": "2017-10-03",
"pages": 461,
"description": "When billionaire researcher Edmond Kirsch is killed,
it is up to Robert Langdon and Ambra Vidal to honor
his memory by making public his findings concerning
the origin of human life and its destiny."
}
}
YAML 和 JSON 之间的区别是:
YAML | JSON |
---|---|
Comments are denoted with a hash/number sign. | Comments are not allowed. |
Hierarchy is denoted by using double space characters. Tab characters are not allowed. | Objects and Arrays are denoted in braces and brackets. |
String quotes are optional but it supports single and double quotes. | Strings must be in double quotes. |
Root node can be any of the valid data types. | Root node must either be an array or an object. |