Toolvito

Works on this device

YAML Formatter & Validator

Paste YAML to check it for mistakes or to make its indentation even. The tool shows the line and column of the first mistake and says what was expected there. Your text is read in this browser and is not uploaded.

Your YAML

Checks the text against the YAML 1.2 rules, shows the place of the first mistake, and lists values that programs do not all read the same way.

Type or paste YAML. It is read on this device and is not uploaded.

More options

Your values are worked out in this browser. They are not sent to a server.

Your result will show here

Type or paste YAML, or choose Try an example.

How to use this tool

  1. Type or paste your YAML in the box, or choose Or open a YAML file from your device. The result updates as you type.
  2. Choose Check if YAML is valid or Format YAML (keeps comments).
  3. To format, choose 2 or 4 spaces for one level, and choose how a list under a key is placed.
  4. Choose Copy text or Download file to keep the result. Download CSV saves the counts and the list of warnings.

What each option does

  • Check if YAML is valid reads the text by the YAML 1.2 rules. If the text is valid, you get counts of documents, mappings, lists, keys and values, and a list of warnings. If it is not valid, you get the line, the column and a short reason, and the line is shown with a mark under the place.
  • Format YAML (keeps comments) changes spacing only. It sets the indentation of mappings and lists, puts one space after each colon and each dash, takes away spaces before a colon and at the end of a line, and writes line ends as LF. Comments, quotes, anchors and the order of keys stay as they are.
  • Allow custom tags is under More options. Tags such as !Ref or !reference belong to one program. With this option the tool checks how they are written, keeps each value as plain data, and lists every such tag as a warning. Without it, the tool stops at the first custom tag.
  • Accept lines without indentation inside brackets and quotes is also under More options. When a value in [ ], { } or quotes goes on to the next line, YAML 1.2 wants that line indented more than its key. Many programs read such a line with no indentation, for example a closing ] in the column of its key. With this option the tool reads it too and lists each such line as a warning, and the formatter indents those lines.

The formatter proves its result

A formatter that reads YAML into data and writes it again loses comments and anchors, and it can change a value. This formatter works on your text. It moves the start of lines and changes the spaces between a key, its colon and its value. It does not write any value again.

After formatting, the tool reads its own result and compares it with your text: the same documents, keys, values, quotes, anchors and comments, in the same order. If anything is different, it shows no result at all.

Values that programs do not all read the same way

This tool reads YAML 1.2 with its core schema. Many programs still use readers made for the older YAML 1.1, which takes more words as true, false, numbers or dates. The check lists every value and key of this kind, with its line and column. Put such a value in quotes to make it text for every reader.

How one value is read by YAML 1.2 and by the older YAML 1.1
Written without quotes YAML 1.2 (this tool) Older YAML 1.1 readers
yes, no, on, off text true or false
010 the number 10 the number 8 (octal)
0o10 the number 8 (octal) text
1_000 text the number 1000
0b101 text the number 5 (binary)
12:30 text the number 750 (base 60)
2001-12-14 text a date
1e3 the number 1000.0 text for some readers
<< text a merge key

The YAML that is read

  • Mappings and lists written with indentation, also the short forms - key: value and - - item, and a list that starts in the column of its key.
  • Mappings in { } and lists in [ ], on one line or on several lines.
  • Text without quotes, in single quotes and in double quotes, on one line or on several lines, with every escape of YAML 1.2 in double quotes.
  • Blocks of text that start with | (line breaks are kept) or > (lines are joined), with the signs + and - and with an indentation number.
  • Comments, several documents in one text, the marks --- and ..., and the line %YAML 1.2.
  • Anchors (&name) and aliases (*name).
  • The tags !!str, !!int, !!float, !!bool, !!null, !!map, !!seq and !.
  • Values without quotes by the core schema: null, ~ and an empty value are null; true and false are true and false; whole numbers in base 10, in base 8 with 0o and in base 16 with 0x; numbers with a decimal point or an exponent; .inf, -.inf and .nan. Everything else is text.

The YAML that is not read

Some parts of YAML are rare in settings files, and this tool does not read them. When it meets one, it stops, names the part and gives its place. It never guesses. The result then says This tool cannot read this YAML, which does not mean that the text is wrong.

  • Keys that are not one line of text: a key that starts with ?, a list or a mapping used as a key, an alias used as a key, and a key with no text.
  • An anchor or a tag on a key, as in &a key: value.
  • A key: value pair directly inside [ ], without { }.
  • The %TAG line and every other line that starts with %, except %YAML.
  • Tags of other type sets such as !!binary, !!timestamp, !!set or !!python/object, tags in the long form !<...>, and tags with a named handle such as !e!name. No tag can make this tool build anything but plain data.
  • Anchor names with characters other than letters, digits, _, - and ..
  • An alias that points to a value which contains that alias.
  • An indentation number on a block of text at the top level of a document, such as --- |2. Programs do not agree on what it means there.

Common mistakes and what the tool says

  • A tab used for indentation. YAML allows only spaces at the start of a line. The tool points to the tab.
  • A missing space after a colon. key:value is one piece of text, not a key and a value. The tool tells you when the next line shows that a space is missing.
  • Uneven indentation. All keys of one mapping must start in the same column, and so must all dashes of one list. A line that is indented a little more than the key above it is read as more text of that key's value.
  • A quote or a bracket that is not closed. The tool gives the place where the quote or bracket starts.
  • The same key twice in one mapping. YAML does not allow it. The tool gives both places.
  • A line of a long value that is not indented. When a value in quotes or in brackets goes on to the next line, that line must be indented more than its key. Some programs accept less; the YAML 1.2 rules do not. An option under More options reads such lines as those programs do.

Worked example

The text below has 3 lines. The third line starts with 3 spaces, but the key above it starts with 2.

shop: / name: Sample Shop / open: true

The check gives Line 3, column 4. The third line is indented more than name, so YAML reads it as more text of the value Sample Shop, and a key and a value are not allowed inside that text. With 2 spaces before open, the text is valid.

Choose Try an example to load a text of 13 lines for a sample shop. The check says Valid YAML with 1 document, 4 mappings, 2 lists, 11 keys, 2 floats and 1 warning: at line 4, column 11 the value yes is text in YAML 1.2, and older readers take it as true. The format option with 2 spaces changes 8 of the 13 lines. For example name: Sample Shop becomes name: Sample Shop, and - name: notebook becomes - name: notebook. The comment in line 1 and the list [paper, pens, ink] stay as they are.

Limits you should know

  • Valid YAML has no writing mistakes. It does not mean that the keys and values are the ones that Kubernetes, Ansible, a build service or any other program expects. This tool does not know the rules of those programs.
  • The check stops at the first mistake. Correct it and run the check again to find the next one.
  • The tool takes up to 1,000,000 characters, data nested up to 100 levels deep, keys up to 1,024 characters, and up to 250,000 values when all aliases are written out. A text that grows past that limit through aliases is refused, so a small text cannot fill the memory.
  • The same key twice in one mapping is reported as a mistake. Some programs accept it and use the last value.
  • The formatter does not change the text inside [ ] and { }, the text of blocks that start with | or >, or the spaces before a comment that follows a value. It does not sort keys and it does not change quotes.
  • A text that is not valid YAML is not formatted. The tool does not correct mistakes for you; it shows where the first one is.
  • The reader was tested with examples of the YAML 1.2 specification and with a second reader written for the tests. It was not yet run against the public YAML test suite.
  • A YAML file from an address on the web cannot be opened here. Copy the text and paste it, or save the file and open it.

Related tools