在线免费JSON转YAML
即时将JSON转换为可读的YAML格式。
Who uses the JSON转YAML?
- 把 Terraform 或 CloudFormation 的 JSON 输出转换为 YAML 格式的云工程师。
- 从文档中的 JSON API 示例出发编写 Kubernetes 清单的开发者。
- 在本地配置中偏好 YAML 可读性优于 JSON 的配置文件作者。
How the JSON转YAML works
把你的 JSON 粘贴到输入框中——对应的 YAML 会立即呈现。
需要加引号的字符串(含特殊字符或空字符串)会自动加上引号。
复制 YAML 输出,用于 Kubernetes、Docker Compose、Ansible 或其他基于 YAML 的工具。
无效的 JSON 会显示明确的解析错误,而不是错误的结果。
Tips & tricks
- 输出缩进固定为 2 个空格——如果目标工具需要 4 个空格,你需要手动重新格式化。
- 含有特殊字符(冒号、引号、首尾空格)的字符串会自动加上引号,以保持 YAML 有效。
- 这是一个单向转换器——如需从 YAML 转回 JSON,请使用本站单独提供的 YAML 转 JSON 工具。
- 在用 kubectl 应用转换后的 YAML 之前,请先清理 Kubernetes API 响应中的元数据(resourceVersion、uid 等)。
Frequently Asked Questions
如何把 JSON 对象转换为 YAML?
JSON:{"name": "John", "age": 30} → YAML:name: John / age: 30。JSON 数组:[1, 2, 3] → 带前导短横线的 YAML 列表项。嵌套对象使用带缩进的子键表示。
这个工具会给 YAML 输出添加注释吗?
不会。JSON 没有注释语法,因此没有内容可以携带过来,本工具也不会自动添加说明性注释——输出只是对你的 JSON 做的直接结构转换。
可转换的 JSON 有大小限制吗?
没有硬性限制——转换完全在你的浏览器中通过 JSON.parse 完成,因此实际限制取决于浏览器的内存,而不是工具本身。非常大的文件(几十 MB)可能会显得较慢。
转换出的 YAML 能直接在 Kubernetes 中使用吗?
如果这份 JSON 代表一个有效的 Kubernetes 资源,转换出的 YAML 应该可以作为有效的 kubectl 输入。不过,Kubernetes JSON API 的响应中通常包含额外的元数据字段——应用 YAML 之前请先清理这些字段。
我可以更改缩进宽度吗?
不可以——输出始终使用 2 个空格缩进,这是最常见的 YAML 惯例(GitHub Actions、Kubernetes 和 Docker Compose 都采用)。没有切换到 4 个空格的设置。
Is my data safe when using the JSON转YAML?
Completely safe. The JSON转YAML processes everything locally in your browser. No input data, results, or usage information is ever transmitted to or stored on any server.
Can I use the JSON转YAML output in commercial projects?
Yes. The JSON转YAML is a utility tool and its output carries no licensing restrictions. You are free to use results in any project, commercial or personal.
Does the JSON转YAML follow official standards?
Yes. The JSON转YAML is built to comply with the relevant industry standard or specification for this utility type. If you encounter an unexpected result, verify your input against the specification — edge cases outside the standard may produce undefined behaviour.