YAML Formatter
Paste YAML to check its syntax and reprint supported values in block layout. This page opens in Format mode. Choose two or four spaces and either keep or sort mapping keys; sequences keep their order. The result is a new serialization of parsed values, so read the notes on comments, aliases and merge keys before replacing a configuration file.
service:
name: gizmobench
port: 8080
debug: "yes"
tags:
- b
- a
retries: 3
Valid: no problems, 1 document, read as YAML 1.2 core.
The data this document resolves to
The data this document resolves to under the YAML 1.2 core schema, printed as JSON.
{
"service": {
"name": "gizmobench",
"port": 8080,
"debug": "yes",
"tags": [
"b",
"a"
]
},
"retries": 3
}- error at 4:1, first at 2:1
- debug is the string "yes"
- stopped at 5:8, nothing parsed
The YAML this page reads
The reader here was written for this page rather than taken from a library, so the honest thing is to publish what it handles. The first list is what it reads. The second is what it reports by name instead of guessing at, which is the part a validator usually leaves you to find out.
Read
- Block mappings and block sequences, nested to any depth this page reads
- Compact sequence items (a mapping that starts on the dash line)
- Flow collections: [1, 2] and {a: 1}, including empty and multi-line ones
- Plain, single-quoted and double-quoted scalars, with the double-quoted escapes
- Block scalars: | and >, with the - and + chomping indicators
- Anchors, aliases and a counted expansion budget
- Several documents in one file, separated by --- and ...
- Comments, counted and kept out of the data
- The core schema tags !!str, !!int, !!float, !!bool, !!null, !!map and !!seq
- An explicit !!bool accepts the older yes, no, on and off spellings
Reported, not read
- Merge keys: << is reported as a warning and left as an ordinary key, not merged
- The explicit key form: a line that starts with ? is reported, not read
- A quoted scalar spread over several lines: use a block scalar instead
- Custom and language tags, including !!binary: reported by name, never resolved
- %TAG directives and tag shorthands beyond the core set
- Comments in format mode: the formatter re-prints the parsed data, so comments are counted and dropped
- Timestamps, sexagesimals and the other YAML 1.1 types: they stay strings, which is what YAML 1.2 core says
Every problem this page can report
All 17 of them, each with the line and the column of what it found. A warning is a note about how something resolved and leaves the document valid; an error does not.
| Code | Kind | What it means |
|---|---|---|
| tab-indent | error | A tab is used to indent a line. YAML never allows one. |
| bad-indent | error | A line does not line up with the block it is in. |
| bad-value | error | A line is not a key and a value, or there is more after the value ends. |
| duplicate-key | error | The same key appears twice in one mapping. Both lines are named. |
| unclosed-quote | error | A quoted scalar is not closed on its line. |
| bad-escape | error | A double-quoted scalar carries an escape YAML does not define. |
| unclosed-flow | error | A [ or { is never closed. |
| flow-syntax | error | A flow collection is missing a comma or a closing bracket. |
| explicit-key | error | The explicit key form, a line starting with ?, is not read here. |
| undefined-alias | error | An alias names an anchor that was never defined above it. |
| alias-budget | error | Alias expansion passed the node budget, so nothing was parsed. |
| unsupported-tag | error | A tag outside the core schema is refused by name and never resolved. |
| tag-mismatch | error | A core tag does not fit its value, such as !!int on a word. |
| depth | error | Nesting goes deeper than this page reads. |
| merge-key | warning | The merge key << is a YAML 1.1 extension and stays an ordinary key here. |
| directive | warning | A directive line is noted; only %YAML is understood. |
| stopped | error | The reader stopped early because it could not make progress. |
Up to 500,000 characters in one pass, read here in your browser with nothing uploaded and no account. Nothing in the document is ever run or fetched: a tag is a string to the reader, a URL is a string, and alias expansion stops after 10,000 copied nodes. Nesting is read 100 levels deep, and the data panel prints the first 20,000 characters of the result. The mode, the two format options and the draft are kept in this browser alone, drafts up to 100,000 characters, and the Start over control above the tool forgets them.
Common questions
- How do I format a YAML or YML file?
- Copy its contents into the input, fix reported errors, inspect the formatted result and use Copy YAML. .yml and .yaml contain the same format. The page has no file picker or download action; save the copied text in your own editor.
- Does formatting keep comments, aliases and flow style?
- Comments are counted and dropped. Anchors and aliases are expanded into values, and flow-style collections become block layout; their original spellings are not preserved. A merge key << is warned about and left as an ordinary key rather than merged. This is not a round-trip editor for exact YAML source.
- Can I sort YAML keys or change the indentation?
- Yes. Choose two or four spaces and Keys kept or sorted. Sorting applies to mappings while sequence order stays unchanged. Under the YAML 1.2 core rules, ambiguous strings such as yes are printed with quotes so another reader is less likely to change their type.
- Can I format Kubernetes or Ansible YAML?
- The supported untagged YAML values can be formatted. The page does not validate application fields, evaluate Helm or other templates, resolve custom tags or perform security linting. A clean format is not proof that Kubernetes, Ansible or a CI service will accept the file.
- Can it convert JSON to YAML or YAML to JSON?
- Use [YAML to JSON](/yaml-to-json), which includes both directions and reports conversion warnings. Formatting YAML here does not produce JSON or translate an application schema.
- How large a document can it format?
- Up to 500,000 characters, 100 nesting levels and 10,000 copied alias nodes in the documented subset. The reader stops with the reason when a bound is exceeded. Loading the site needs a connection; it is a browser utility, not an editor extension or native offline package.
Read by a YAML 1.2 core-schema parser written for this page, so yes and no are strings, only true and false are booleans, and every problem carries a line and a column. Alias expansion stops at a fixed budget rather than hanging the page, a tag outside the core set is refused by name, and the subset this parser reads is listed under the tool. Your document is read in this browser and nothing it names is ever fetched.