JSON to YAML
Convert JSON data into readable YAML
JSON to YAML — what it does
Convert JSON into YAML, trading braces and quotes for indentation and plain keys. The two formats carry the same data model, but YAML is what configuration files use in practice — Kubernetes, CI pipelines, Docker Compose and Ansible all read it, and humans edit it far more comfortably.
Worked example
A service configuration object converted with the Convert button.
JSON input
{
"service": "billing-api",
"replicas": 3,
"env": {"LOG_LEVEL": "info", "DEBUG": "no", "PORT": "8080"},
"owners": ["ann.lee@example.com", "mark.chen@example.com"],
"description": "Handles invoices: monthly & on demand",
"enabled": true,
"retry": null,
"notes": ""
}Output — YAML
service: billing-api replicas: 3 env: LOG_LEVEL: info DEBUG: 'no' PORT: '8080' owners: - ann.lee@example.com - mark.chen@example.com description: 'Handles invoices: monthly & on demand' enabled: true retry: null notes: ''
Strings that YAML would otherwise read as something else are quoted automatically: 'no' (a boolean in YAML 1.1), '8080' (a number) and the description, because it contains ": ". The empty string becomes '' and null stays null.
When this tool helps
- Turning a JSON configuration into the YAML a deployment tool expects.
- Making a nested payload readable for documentation or a code review.
- Converting an exported settings file into a format a colleague can edit by hand.
How to use it
- Paste the JSON input.
- Process the conversion.
- Review the YAML output.
- Copy it into your configuration file.
Accuracy, limits, and good practice
- YAML is indentation-sensitive and forbids tabs, which is the single most common reason a hand-edited file suddenly fails to parse.
- Values like yes, no, on and off can be read as booleans in some parsers; quote them when you mean the literal words.
- Comments are YAML's real advantage over JSON for configuration — add them after converting to explain the non-obvious settings.
- Long string values are where YAML earns its keep: block scalars keep a multi-line script or certificate readable instead of one escaped line.
Frequently asked questions
Is YAML a superset of JSON?
Effectively yes for current versions: valid JSON is valid YAML, though the reverse is not true.
Why do teams prefer YAML for config?
Comments, less punctuation and multi-line strings. For machine-to-machine payloads, JSON remains the better choice.
How do I convert back?
The YAML to JSON tool parses YAML and outputs formatted JSON.
Does the key order stay the same?
Order is preserved in the output, though neither format assigns meaning to it — parsers may return keys in any order.
How are multi-line and very long strings written?
A string containing line breaks becomes a literal block (script: |- followed by the lines), and a single-line string longer than about 100 characters is folded onto several lines with >-. Both read back as the identical string; the 100-character width is fixed.
What does the error look like for invalid JSON?
The browser's JSON parser message appears in the status line, for example "Expected double-quoted property name in JSON at position 7 (line 1 column 8)" for a trailing comma, and the output box is left unchanged. Comments and single quotes are JSON errors too, so strip them before converting.
Related tools on this site
- CSS Box Shadow Generator — Design a box shadow visually and copy production-ready CSS
- JavaScript Formatter & Minifier — Beautify, validate, or minify JavaScript code in the browser
- Morse Code Converter — Encode text as Morse code or decode Morse back to text
Further reading: Cleaning Up Text You Pasted From Somewhere Else
Everything above runs inside this page. JSON to YAML needs no account, no upload, and no server round trip — close the tab and nothing is left behind.
JSON 轉 YAML能做什麼
把 JSON 轉成 YAML,用縮排與素樸的鍵名換掉大括號與引號。兩者的資料模型相同,但實務上設定檔用的是 YAML——Kubernetes、CI 流程、Docker Compose 與 Ansible 都讀它,人編輯起來也舒服得多。
實際範例
一份服務設定物件,按下轉換。
原文:JSON
{
"service": "billing-api",
"replicas": 3,
"env": {"LOG_LEVEL": "info", "DEBUG": "no", "PORT": "8080"},
"owners": ["ann.lee@example.com", "mark.chen@example.com"],
"description": "Handles invoices: monthly & on demand",
"enabled": true,
"retry": null,
"notes": ""
}轉換後:YAML
service: billing-api replicas: 3 env: LOG_LEVEL: info DEBUG: 'no' PORT: '8080' owners: - ann.lee@example.com - mark.chen@example.com description: 'Handles invoices: monthly & on demand' enabled: true retry: null notes: ''
YAML 可能誤讀的字串會自動加引號:'no'(YAML 1.1 的布林值)、'8080'(數字)以及含「: 」的 description。空字串變成 '',null 維持 null。
什麼時候用得上
- 把 JSON 設定轉成部署工具期待的 YAML。
- 為文件或程式碼審查,把巢狀載荷變得可讀。
- 把匯出的設定檔轉成同事能手動編輯的格式。
使用步驟
- 貼上 JSON 輸入。
- 執行轉換。
- 檢視 YAML 輸出。
- 複製到你的設定檔中。
精確度、限制與實務建議
- YAML 對縮排敏感且不允許 Tab,這是手動編輯後突然解析失敗最常見的原因。
- yes、no、on、off 在某些解析器中會被當成布林值;要表達字面文字時請加引號。
- 註解才是 YAML 用於設定時勝過 JSON 的真正優勢——轉換後請補上說明,解釋那些不直觀的設定。
- 長字串正是 YAML 發揮價值的地方:區塊純量能讓多行腳本或憑證維持可讀,而不是擠成一行逸出字元。
常見問題
YAML 是 JSON 的超集嗎?
以現行版本而言實質上是:合法的 JSON 就是合法的 YAML,反過來則不成立。
為什麼團隊偏好用 YAML 寫設定?
因為可加註解、標點少、支援多行字串。至於機器之間的載荷,JSON 仍是更好的選擇。
怎麼轉回去?
YAML 轉 JSON 工具會解析 YAML 並輸出格式化的 JSON。
鍵的順序會維持嗎?
輸出會保留順序,但兩種格式都不賦予順序意義,解析器回傳的順序可能不同。
多行與很長的字串會怎麼寫?
含換行的字串會寫成字面區塊(script: |- 之後逐行呈現),超過約 100 個字元的單行字串則以 >- 折成多行。兩種寫法讀回來都是一模一樣的字串;100 字元的寬度是固定的。
JSON 不合法時的錯誤長什麼樣?
瀏覽器 JSON 解析器的訊息會顯示在狀態列,例如多了一個尾端逗號會得到「Expected double-quoted property name in JSON at position 7 (line 1 column 8)」,而轉換框維持原狀。註解與單引號在 JSON 裡同樣是錯誤,轉換前請先拿掉。
本站相關工具
- CSS 陰影生成器 — 以視覺方式設計方塊陰影並複製 CSS
- JavaScript 格式化與壓縮 — 在瀏覽器中美化、驗證或壓縮 JavaScript 程式碼
- 摩斯密碼轉換器 — 將文字編碼為摩斯密碼或解碼回文字
延伸閱讀: 清理從別處貼上的文字
以上步驟全部在這個頁面內完成,JSON 轉 YAML 不需要註冊、不上傳檔案、也不經過伺服器,關閉分頁後不會留下任何資料。