Monu Tools

YAML 转 JSON 转换器

将 YAML 转为 JSON,也可将 JSON 转回 YAML,双向均可。转换时进行校验并显示清晰的错误。一切都在浏览器中运行。

如何使用 YAML ⇄ JSON

  1. 01

    选择方向:YAML 转 JSON 或 JSON 转 YAML。

  2. 02

    将你的 YAML 或 JSON 粘贴到输入面板。

  3. 03

    复制转换后的结果,如果输入无效则查看错误。

What it does

This converter transforms YAML into JSON and JSON into YAML, in both directions. Pick the direction, paste your input, and copy the converted result or read a clear error if the input is malformed.

Everything is processed locally in your browser, so your data stays on your device.

How the two formats differ

YAML and JSON describe the same kind of data, but with different priorities. JSON is strict and compact, which suits APIs and machines; YAML is indentation-based and easier for people to read and edit, which is why it dominates configuration files.

Validation and the parser

Each conversion parses the source first, so malformed input is caught and reported with the reason and often the line, instead of silently producing a broken result. A successful conversion therefore also tells you the input was valid.

It uses the YAML 1.2 and 1.1 compatible parser from js-yaml, covering the features you meet in practice: mappings, sequences, scalars, anchors and multi-line strings.

Where it fits, and the comment caveat

This is exactly the glue you need around CI pipelines, Kubernetes and Docker Compose files, and APIs that speak JSON while your config is written in YAML. It lets you move between the two without hand-editing.

One thing to know: YAML comments are dropped, because JSON has no concept of comments, and converting back generates fresh YAML without them.

常见问题

支持哪个 YAML 版本?

它使用 js-yaml 中兼容 YAML 1.2 / 1.1 的解析器,涵盖常见特性:映射、序列、标量、锚点和多行字符串。

为什么我会收到错误?

输入会在转换前被解析,因此无效的 YAML 或 JSON 会显示带原因的提示,通常还包含行号,帮助你快速发现问题。

注释会被保留吗?

不会。由于 JSON 没有注释,转换过程中 YAML 注释会被丢弃,转回时会生成不含注释的新 YAML。

我的数据会被上传吗?

不会。转换完全在你的浏览器中运行;你粘贴的内容不会离开你的设备。

来源

嵌入此工具

将此工具添加到你自己的网站。复制下方代码片段即可,它会自动保持最新。

<iframe src="https://monu.tools/embed/zh/yaml-json-converter" width="100%" height="640" style="border:1px solid #e5e5e5;border-radius:12px;max-width:680px" loading="lazy" title="Monu Tools"></iframe>

相关工具