YAML Validator
Paste a document and see what is wrong with it, with the line and the column on every problem and the data it resolves to printed underneath. What is different here is that the schema is named and its consequences are shown: this page reads YAML 1.2 core, so debug: yes is the string "yes" and the panel says so in as many words, rather than quietly handing you a boolean the way a YAML 1.1 reader would. A key defined twice is an error that names both lines and tells you which value wins. A tab used to indent is caught by line and column instead of producing a confusing error further down. Anchors and aliases are expanded against a counted budget, so the chain of anchors that people use to test parsers stops and says where it stopped. The reader was written for this page rather than taken from a library, so the subset it handles and the 17 problems it can report are both published under the tool. Switch Validate to Format and the same parse is re-printed at two or four spaces, with keys kept or sorted.
- 4:1errorduplicate-keyDuplicate key "port": it is defined twice in the same mapping, and the one on line 4 is the value that resolves. Remove one of them.first defined at 2:1
YAML 1.2 core schema
debug is the string "yes"
port would resolve to 9090
Invalid: 1 problem, 1 document, read as YAML 1.2 core. First at 4:1: Duplicate key "port": it is defined twice in the same mapping, and the one on line 4 is the value that resolves. Remove one of them.
The data this document resolves to
The data this document resolves to under the YAML 1.2 core schema, printed as JSON.
{
"name": "gizmobench",
"port": 9090,
"debug": "yes",
"tags": [
"a",
"b"
]
}- 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
- Why does this say debug: yes is a string, not true?
- Because that is what YAML 1.2 says, and it is the single most common surprise in a config file. The 1.2 core schema resolves only true, True, TRUE, false, False and FALSE as booleans; yes, no, on, off, y and n are ordinary strings. YAML 1.1 read them as booleans, which is why the same file can mean two different things to two different tools, and why a Norwegian country code written as no is famous for it. This page prints a note beside the result, such as debug is the string "yes", so the difference is visible instead of silent. If you want a boolean, write true, or tag the value !!bool yes. If you want the string to survive whatever reads the file next, run Format: it quotes the value as debug: "yes".
- Why is a tab not allowed to indent YAML?
- The specification forbids it: indentation in YAML is spaces only, because a tab has no defined width and the structure of the document is its indentation. An editor that inserts a tab therefore breaks a file that looks fine on screen. This page reports it as tab-indent with the line and the column of the tab, and parses nothing until it is fixed, because the nesting is not knowable while a tab is in there. Replace each tab with spaces, two per level is the usual choice, and the data panel fills in.
- Does it catch a key defined twice?
- Yes, and it names both lines. In the sample document the second port is reported at 4:1 with first defined at 2:1 beside it, and the note says port would resolve to 9090, which is the value a reader that accepts the file would use. Duplicate keys are an error in YAML, but plenty of readers take the last one quietly, so a config can be doing something other than what it looks like it does. The check compares resolved values, so 1 and 01 collide while 1 and "1" do not.
- What happens to anchors and aliases, and to a YAML bomb?
- An anchor defined with &name is expanded wherever *name appears, and the expansion is counted. The budget is 10,000 copied nodes: past that the reader stops, reports alias-budget with the line and column of the alias that broke it, and parses nothing. That is what the billion laughs document does, a chain of anchors where each one repeats the one above it nine times, and it is why a validator that expands first and asks questions later can hang a tab. An alias with no anchor above it is reported by name. Merge keys are different: << is a YAML 1.1 extension, so it is reported as a warning and left as an ordinary key rather than merged.
- Can it format YAML as well as check it?
- Yes. Switch the control beside the result from Validate to Format and the parsed data is re-printed: two or four spaces per level, keys kept in their original order or sorted, flow collections such as [b, a] expanded into block style. Values are preserved under any reader, so a string that another parser would call a boolean comes back quoted, and 010 comes back as 10 because YAML 1.2 reads it as ten rather than as octal. Comments are the honest limit: the formatter re-prints the data it parsed, so comments are counted and not carried over, and the page says how many there were.
- Is my document uploaded, and what does this page not read?
- Nothing is uploaded and nothing is fetched. The parser runs in your browser, a URL in the document is a string to it, and a tag outside the core set is refused by name rather than resolved, so a file carrying something like !!python/object/apply cannot do anything here. The subset it reads is published under the tool, and so is what it does not: merge keys, the explicit key form that starts a line with a question mark, a quoted scalar spread over several lines, custom tags, and %TAG directives. It reads up to 500,000 characters in one pass and 100 levels of nesting, and refuses anything longer rather than cutting it down to fit.
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.