YAML Validator

Paste YAML and see at once whether it parses, and if not, which line to fix.

Checked in your browser. Your YAML is never uploaded. How we know

Reformat CtrlEnter

0 lines
or drop a .yaml or .yml file
JSON
 

Your YAML is checked as you type. Valid YAML is shown here as JSON.

Ln 1, Col 1 Spaces: 2 UTF-8
Processed in this tab

Processed in this tab

How to validate YAML

There is no button to press. The file is checked as you type, and nothing leaves your browser.

  1. Paste or open. Paste YAML into the left pane, use Open file for a .yaml or .yml file, or drop the file onto the pane.
  2. Read the result. The status reads Valid YAML with the number of documents, or names the line of the first error.
  3. Fix and repeat. The error card gives the line and column, the cause and the fix. Go to line puts your cursor there.

When the YAML is valid, the right pane shows it as JSON. That is a quick way to check that it means what you intended: you can see at a glance that a value became a string instead of a number, or that a key ended up one level deeper than you wanted.

Common YAML errors and how to fix them

Most invalid YAML comes down to a handful of mistakes. These are the ones the validator names, with the fix for each.

Tab indentation web: ⇥image: nginx
YAML only allows spaces for indentation. Replace each tab with spaces; 2 per level is the usual choice.
Bad indentation image: nginx ports: 80
A key is indented more or less than the keys around it, so YAML can’t tell which map it belongs to. Line up keys of the same level in the same column.
Missing space after colon image:nginx
Without the space, YAML reads the whole line as one piece of text instead of a key and a value. Write image: nginx.
Colon inside a value title: Note: draft
A colon followed by a space starts a new key. Wrap the value in quotes: title: "Note: draft".
Duplicate key name: a name: b
YAML allows each key once per map. Some parsers quietly keep the last one, which hides the mistake. This validator reports it.
Unclosed quote title: "hello
A string is opened but never closed, so the rest of the file is read as part of it. Add the closing quote.
Unclosed bracket or brace ports: [80, 443
A [ or { is never closed. Add the closing ] or }, and check for a missing comma between items.
Unknown alias copy: *defaults
An alias points to an anchor that isn’t defined before it. Define &defaults earlier in the file, or fix the spelling.

What this validator checks

It checks syntax: that the file is well-formed YAML that a parser can read. That covers indentation, quoting, brackets, duplicate keys, aliases without an anchor, and every document in a multi-document file. It follows YAML 1.2, so yes and no are read as text and only true and false are booleans.

It doesn't check a schema. It has no idea which fields Kubernetes, Docker Compose or GitHub Actions expect, so a misspelled field name passes. For that, use the tool's own check, such as docker compose config for a Compose file.

One limit to know about: custom tags, such as CloudFormation's !Ref and !Sub, are reported as unknown tags. They are legal YAML, but the validator has no definition for them.

Validate YAML on the command line

To check a file in a terminal or a CI job, parse it and look at the exit code. Each command prints valid on success, and the parser's error with a line number on failure.

python3 -c 'import sys, yaml; yaml.safe_load(sys.stdin)' < config.yaml && echo valid

Tested with Python 3.11.3 and PyYAML 6.0.1

The two don't always agree. PyYAML follows the older YAML 1.1 and accepts a duplicate key, keeping the last value. js-yaml follows YAML 1.2 and rejects it, as this page does.

More YAML and JSON tools

Every tool here runs in your browser, with the same editor, share links and plain-English errors.

Frequently asked questions

How do I validate a YAML file?

Paste the YAML into the left pane or open the file. The status above the right pane shows Valid YAML with the number of documents, or the line of the first error. For an error you also get the column, the cause in plain English and the fix. It rechecks as you type.

What does “bad indentation of a mapping entry” mean?

It is a parser’s way of saying a key is not lined up with the keys around it. YAML uses indentation to decide which map a key belongs to, so one extra or missing space changes the structure. Put keys of the same level in the same column, using spaces only.

Can I use tabs in YAML?

Not for indentation. The YAML specification forbids tab characters there, and parsers reject them. Tabs are allowed inside a value, for example in a quoted string. Most editors can be set to insert spaces when you press Tab in a .yaml file.

Are duplicate keys valid YAML?

No. The specification says the keys of a map must be unique. In practice some parsers accept a repeated key and keep the last value, so the file seems to work while one of your settings is silently ignored. This validator reports a duplicate as an error.

Does it check my Kubernetes or Docker Compose file against a schema?

No. It checks that the file is well-formed YAML, not that the fields are the ones a tool expects. A misspelled field name is still valid YAML. For that, use the tool’s own check, such as docker compose config for a Compose file.

Is my YAML uploaded anywhere?

No. The check runs in your browser tab, and the page never sends your YAML in any request. That matters for config files, which often hold host names, tokens and passwords. An automated test checks this on every build of the site.