跳到主要内容
Z

What is YAML?

YAML (YAML Ain't Markup Language) is a human-friendly, indentation-based data serialization format used mainly for configuration files. It represents the same data as JSON — scalars, lists and mappings — but with cleaner syntax, comments and multi-line strings, making it popular in CI/CD, Docker and Kubernetes.

YAML uses indentation (spaces, never tabs) to show structure instead of brackets. Mappings are key: value, lists use -, and it supports comments (#), multi-line strings and anchors/references for reuse. Because YAML is a superset of JSON, any JSON is valid YAML.

Its readability makes it the default for human-edited configuration — GitHub Actions, Docker Compose, Kubernetes manifests — where comments and clean diffs matter.

YAML tools

常见问题

为什么有些字符串会加引号,有些却不加?

js-yaml 只会给可能被误判为其他数据类型(数字、布尔值、日期)或包含特殊字符的字符串加上引号。不加引号的写法因为更易读而被优先采用。

该工具会保留键的原始顺序吗?

会,默认情况下会保留 JSON 对象中键的原始顺序。启用“排序键”可以按字母顺序输出。

该工具能处理层级非常深的嵌套结构吗?

js-yaml 本身没有固定的深度限制,但过深的嵌套结构(超过 100 层)可能会触发 JS 引擎的递归限制。