Y

YAML to JSON

Parse YAML and export formatted JSON

YAML to JSON — what it does

Parse a YAML document and output formatted JSON. The two formats describe the same data model, so the conversion is lossless in structure — what changes is the audience: YAML for humans editing configuration, JSON for programs consuming it.

Worked example

A service manifest converted to JSON. The release date is deliberately left unquoted and the version is quoted, to show how each comes through.

Input — YAML

service: invoice-api
release: 2026-10-20
version: "2.4"
replicas: 3
debug: false
owners:
  - ann.lee@example.com
  - b.tran@example.com
limits:
  memory: 512Mi

Output — JSON

{
  "service": "invoice-api",
  "release": "2026-10-20T00:00:00.000Z",
  "version": "2.4",
  "replicas": 3,
  "debug": false,
  "owners": [
    "ann.lee@example.com",
    "b.tran@example.com"
  ],
  "limits": {
    "memory": "512Mi"
  }
}

The unquoted date became the timestamp string "2026-10-20T00:00:00.000Z", while the quoted "2.4" stayed a string and 3 and false became a number and a boolean.

When this tool helps

  • Feeding a YAML configuration into a tool or API that only accepts JSON.
  • Inspecting a YAML file's structure unambiguously, with explicit brackets and quotes.
  • Converting a configuration file for a system that has moved from YAML to JSON.

How to use it

  1. Paste the YAML input.
  2. Process the conversion.
  3. Review the JSON output.
  4. Copy it into your tool or file.

Accuracy, limits, and good practice

  • Converting to JSON is a good validation step in itself: if the YAML is malformed, the conversion fails and tells you where.
  • Comments are lost, because JSON has no comment syntax — keep the YAML as the source of truth where the notes matter.
  • Unquoted YAML values can convert to a type you did not intend: a version number like 1.20 becomes the float 1.2 unless it was quoted.
  • Convert as a review step before deploying a manifest: reading the JSON makes the actual structure explicit where YAML indentation only implies it.

Frequently asked questions

Is the conversion lossless?

Structurally yes, but comments and formatting are lost, and YAML anchors are expanded rather than preserved.

Why did my value change type?

YAML infers types from unquoted text. Quote values that must stay strings, especially version numbers and yes-or-no words.

Can I convert back?

Yes, the JSON to YAML tool converts in the other direction, though comments cannot be recovered.

What happens to multi-line block scalars?

They become ordinary JSON strings with escaped newlines, which is correct but noticeably less readable than the YAML original.

Why did my date turn into a timestamp with T00:00:00.000Z?

An unquoted value in the form YYYY-MM-DD is parsed as a date, and dates are serialised in JSON as full UTC timestamps. Quote the value ("2026-10-20") in the YAML to keep it as the plain string you wrote. The same applies to values like 2026-10-20 09:30:00.

Can I convert a file with several documents separated by ---?

No. The parser accepts a single document; with a second --- document it stops with "expected a single document in the stream, but found more" in the status line, and the output box keeps whatever the previous successful conversion produced. Convert each document separately. A single leading ---, with no second document after it, is fine.

Related tools on this site

Everything above runs inside this page. YAML to JSON needs no account, no upload, and no server round trip — close the tab and nothing is left behind.

YAML 轉 JSON能做什麼

解析 YAML 文件並輸出格式化的 JSON。兩種格式描述的是同一套資料模型,因此結構上是無損轉換——改變的是讀者:YAML 給編輯設定的人,JSON 給讀取設定的程式。

實際範例

一份服務清單轉成 JSON。發布日期刻意不加引號、版本號則加了引號,以呈現兩者各自的轉換方式。

來源:YAML

service: invoice-api
release: 2026-10-20
version: "2.4"
replicas: 3
debug: false
owners:
  - ann.lee@example.com
  - b.tran@example.com
limits:
  memory: 512Mi

轉換後:JSON

{
  "service": "invoice-api",
  "release": "2026-10-20T00:00:00.000Z",
  "version": "2.4",
  "replicas": 3,
  "debug": false,
  "owners": [
    "ann.lee@example.com",
    "b.tran@example.com"
  ],
  "limits": {
    "memory": "512Mi"
  }
}

未加引號的日期變成了時間戳記字串「2026-10-20T00:00:00.000Z」,加了引號的 "2.4" 維持字串,3 與 false 則分別變成數字與布林值。

什麼時候用得上

  • 把 YAML 設定送進只接受 JSON 的工具或 API。
  • 以明確的括號與引號,毫無歧義地檢視 YAML 檔的結構。
  • 為已從 YAML 改用 JSON 的系統轉換設定檔。

使用步驟

  1. 貼上 YAML 輸入。
  2. 執行轉換。
  3. 檢視 JSON 輸出。
  4. 複製到你的工具或檔案中。

精確度、限制與實務建議

  • 轉成 JSON 本身就是一種驗證:YAML 有問題時轉換會失敗,並指出出錯的位置。
  • 註解會遺失,因為 JSON 沒有註解語法——註解重要時請以 YAML 作為單一真實來源。
  • 未加引號的 YAML 值可能轉成非預期型別:1.20 這種版本號若沒加引號會變成浮點數 1.2。
  • 部署清單前把轉換當成一道檢查:YAML 用縮排暗示的結構,讀 JSON 時會變得明明白白。

常見問題

轉換是無損的嗎?

結構上是,但註解與排版會遺失,YAML 錨點會被展開而非保留。

我的值型別為什麼變了?

YAML 會從未加引號的文字推斷型別。必須維持字串的值請加引號,版本號與 yes/no 這類詞尤其要注意。

可以轉回去嗎?

可以,JSON 轉 YAML 工具負責反方向,只是註解無法還原。

多行區塊純量會怎樣?

會變成帶逸出換行的一般 JSON 字串,內容正確,但可讀性明顯不如原本的 YAML。

為什麼我的日期變成帶 T00:00:00.000Z 的時間戳記?

YYYY-MM-DD 形式、未加引號的值會被解析成日期,而日期在 JSON 裡會序列化成完整的 UTC 時間戳記。在 YAML 裡把值加上引號("2026-10-20")就能保留你寫的純字串。像 2026-10-20 09:30:00 這類值也一樣。

可以轉換含多份以 --- 分隔的文件嗎?

不行。解析器只接受單一文件;遇到第二份 --- 文件時會中止,狀態列顯示「expected a single document in the stream, but found more」,而原本的 JSON 方框會保留上一次成功轉換的內容。請把每份文件分開轉換。單獨一個開頭的 ---、後面沒有第二份文件的話則沒有問題。

本站相關工具

以上步驟全部在這個頁面內完成,YAML 轉 JSON 不需要註冊、不上傳檔案、也不經過伺服器,關閉分頁後不會留下任何資料。