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-Hant/yaml-json-converter" width="100%" height="640" style="border:1px solid #e5e5e5;border-radius:12px;max-width:680px" loading="lazy" title="Monu Tools"></iframe>

相關工具