YAML Formatter & Validator
Validate and consistently format YAML documents
YAML Formatter & Validator — what it does
Validate a YAML document and reformat it with consistent indentation and structure. YAML's readability depends entirely on its indentation being correct, and a single misplaced space is the difference between a working configuration and a deployment that refuses to start.
Worked example
A deployment config with uneven spacing, a comment, four-space indentation and a flow-style list, run through the formatter. The output is re-emitted with two-space indentation and block-style lists.
Input — YAML
# deploy config
app: invoice-api
version: 1.10
replicas: 3
enabled: yes
env:
DATABASE_URL: "postgres://db.example.com/invoices"
LOG_LEVEL: info
ports: [8080, 9090]Output — formatted
app: invoice-api version: 1.1 replicas: 3 enabled: 'yes' env: DATABASE_URL: postgres://db.example.com/invoices LOG_LEVEL: info ports: - 8080 - 9090
The comment is gone, version: 1.10 was parsed as the number 1.1, the unquoted yes stayed a string and is now written as 'yes', and the quotes around the URL were dropped because they are not needed.
When this tool helps
- Checking a Kubernetes manifest, CI pipeline or Docker Compose file before applying it.
- Tidying a configuration file that several people have edited inconsistently.
- Finding the indentation error that a tool reported only as a vague parse failure.
How to use it
- Paste the YAML into the input box.
- Format the document.
- Read the formatted output or the validation error.
- Copy the corrected YAML back into your file.
Accuracy, limits, and good practice
- Tabs are forbidden in YAML indentation. An editor that inserts tabs will produce a file that fails to parse with a confusing message.
- Quote values like yes, no, on, off and version numbers such as 1.10, or a parser may read them as booleans and floats.
- Validate before applying anything to a running system; YAML errors surface at deploy time, which is the worst possible moment to find them.
Frequently asked questions
Why does my YAML fail to parse?
Almost always indentation — a tab character, an inconsistent level, or a list item aligned to the wrong depth.
How many spaces should I indent?
Two is the widespread convention. Consistency matters far more than the specific number.
Does formatting preserve comments?
Comments are not part of the data model, so treat them as at risk during reformatting and check the output.
What happens to anchors, aliases and merge keys?
They are resolved and expanded: an alias becomes a full copy of the anchored content and the &name / *name markers disappear, so a config that shares defaults through <<: *defaults comes back with those keys written out under every section that referenced them. The data is the same, but longer, and the link between the sections is lost.
Why was a long value rewrapped onto several lines?
Lines are wrapped at 100 characters. A plain scalar longer than that is emitted as a folded block (>-) split across indented lines, which any YAML parser reads back as the original single string. Key order is preserved; keys are not sorted.
Related tools on this site
- HTML Formatter — Beautify compressed or difficult-to-read HTML markup
- List Formatter — Convert lines into bullets, numbers, CSV, or JSON
- Text Cleaner — Remove extra spaces, empty lines, and repeated lines
Further reading: Cleaning Up Text You Pasted From Somewhere Else
Everything above runs inside this page. YAML Formatter & Validator needs no account, no upload, and no server round trip — close the tab and nothing is left behind.
YAML 格式化與驗證能做什麼
驗證 YAML 文件並以一致的縮排與結構重新排版。YAML 的可讀性完全建立在縮排正確之上,而一個放錯位置的空格,就是「設定可用」與「部署起不來」之間的差別。
實際範例
一份間距凌亂、含註解、四格縮排與流式清單的部署設定,交給格式化器整頓。轉換後的文字改以兩格縮排與區塊式清單重新產生。
來源:YAML
# deploy config
app: invoice-api
version: 1.10
replicas: 3
enabled: yes
env:
DATABASE_URL: "postgres://db.example.com/invoices"
LOG_LEVEL: info
ports: [8080, 9090]格式化後
app: invoice-api version: 1.1 replicas: 3 enabled: 'yes' env: DATABASE_URL: postgres://db.example.com/invoices LOG_LEVEL: info ports: - 8080 - 9090
註解消失了;version: 1.10 被解析成數字 1.1;未加引號的 yes 仍是字串,現在寫成 'yes';網址外層的引號因不必要而被拿掉。
什麼時候用得上
- 套用前先檢查 Kubernetes 清單、CI 流程或 Docker Compose 檔。
- 整理多人編輯、風格不一的設定檔。
- 找出工具只回報「解析失敗」的那個縮排錯誤。
使用步驟
- 把 YAML 貼進輸入框。
- 執行格式化。
- 閱讀格式化結果或驗證錯誤。
- 把修正後的 YAML 複製回檔案。
精確度、限制與實務建議
- YAML 縮排禁止使用 Tab。會插入 Tab 的編輯器產生的檔案會解析失敗,而且錯誤訊息通常讓人摸不著頭緒。
- yes、no、on、off 以及 1.10 這類版本號請加引號,否則解析器可能把它們讀成布林值與浮點數。
- 套用到執行中的系統之前先驗證;YAML 錯誤往往在部署當下才浮現,而那是最糟的發現時機。
常見問題
我的 YAML 為什麼解析失敗?
幾乎都是縮排——夾了 Tab 字元、層級不一致,或清單項目對齊到錯誤深度。
該縮排幾個空格?
兩個是普遍慣例。一致性遠比用幾個空格更重要。
格式化會保留註解嗎?
註解不屬於資料模型,重新排版時請視為有風險,並檢查輸出結果。
錨點、別名與合併鍵會怎樣?
會被解析並展開:別名變成錨點內容的完整副本,&name 與 *name 標記消失,所以透過 <<: *defaults 共享預設值的設定,回來時每個引到它的區段底下都會把那些鍵完整寫一遍。資料相同但變長了,區段之間的關聯也沒了。
為什麼很長的值被折成好幾行?
每行在 100 個字元處折行。超過這個長度的純量會以折疊區塊(>-)的形式拆成多個縮排的行,任何 YAML 解析器讀回來仍是原本的單一字串。鍵的順序會保留,不會被排序。
本站相關工具
延伸閱讀: 清理從別處貼上的文字
以上步驟全部在這個頁面內完成,YAML 格式化與驗證 不需要註冊、不上傳檔案、也不經過伺服器,關閉分頁後不會留下任何資料。