DevFormatter

YAML Validator

 

YAML Validator

How the YAML Validator works

Last updated: November 2026

A YAML validator checks whether a YAML document is syntactically correct — proper indentation (spaces, never tabs), well-formed mappings and sequences, valid scalar types, and no structural errors. It reports the exact line and column of any problem.

YAML is widely used in Docker Compose, GitHub Actions, Kubernetes, Ansible, and many configuration formats. A single indentation mistake or a stray tab can make an entire config file fail silently or not at all.

All validation runs in your browser using js-yaml v4 — your data never leaves your machine.

YAML Quick Reference

Type YAML syntax Notes
Mapping (object) key: value Space after colon is required
Sequence (array) - item Dash + space; all items at same indent level
String (quoted) "hello\nworld" Double quotes enable escape sequences
String (literal block) |
  line 1
  line 2
Preserves newlines; trailing newline added
String (folded block) >
  long line
  continues
Newlines folded to spaces
Boolean true / false YAML 1.2 only. YAML 1.1 also accepts yes/no/on/off
Null null / ~ Empty value also maps to null
Anchor & alias &name / *name Reuse a node value elsewhere in the document

Tips & Tricks

Tabs are always a syntax error

The YAML spec forbids tabs for indentation. Configure your editor to expand tabs to spaces in YAML files. VS Code: add "editor.insertSpaces": true to yaml language settings.

Quote values that look like booleans

Country codes like NO (Norway), YES (Yesenia), and config values like on/off are silently coerced to booleans by YAML 1.1 parsers. Always quote them: "yes".

Colons in values need quoting

An unquoted value containing a colon followed by a space (e.g. url: http://example.com) will be parsed as a mapping, not a string. Quote URLs: "http://example.com".

Anchors don't deep-merge by default

Using *alias replaces the entire node. Use the merge key <<: *alias to merge mapping keys from an anchor into the current mapping — but this is a YAML 1.1 extension not in YAML 1.2.

Empty values vs null

A key with no value (key:) maps to null in most parsers. An explicitly empty string requires quotes: key: "". These are different and application code may treat them differently.

GitHub Actions uses YAML 1.1

GitHub Actions runs on go-yaml v2 (YAML 1.1). Values like on in a workflow file are keywords — not the string "on". This is why top-level YAML keys like on: [push] must not be quoted in Actions, but string values must be.

YAML 1.1 Coercion Risks

The most dangerous YAML bugs are not syntax errors — they are silent type coercions in YAML 1.1 parsers. PyYAML, Docker Compose (go-yaml v2), and GitHub Actions all use YAML 1.1 and will silently convert these values:

Boolean coercion (yes/no/on/off)

# YAML 1.1 parsers (PyYAML, Docker Compose, GitHub Actions) treat these as booleans:
enabled: yes    # → true
debug: no       # → false
active: on      # → true
disabled: off   # → false

# Fix: quote the values
enabled: "yes"
debug: "no"

Sexagesimal integer coercion (time values)

# YAML 1.1 converts sexagesimal notation to integers:
timeout: 22:30  # → 1350 (22*60 + 30)
port: 8:080     # → 488

# Fix: quote the values
timeout: "22:30"
port: "8:080"

YAML 1.2 parsers (js-yaml v5+, go-yaml v3, ruamel.yaml) do not perform these coercions. Use the YAML Formatter's "Fix 1.1 Risks" button to auto-quote all risky values.

Validate YAML Programmatically

Node.js (js-yaml)

const yaml = require('js-yaml'); // npm install js-yaml
try {
  yaml.load(input);
  console.log('valid');
} catch (e) {
  console.error(e.message); // includes line number
}

Python (PyYAML)

import yaml  # pip install pyyaml
try:
    yaml.safe_load(text)
    print("valid")
except yaml.YAMLError as e:
    print(e)  # includes line and column

CLI

# Python one-liner
python3 -c "import yaml,sys; yaml.safe_load(open(sys.argv[1])); print('valid')" file.yaml

# Node.js with js-yaml
node -e "const y=require('js-yaml'),fs=require('fs'); try{y.load(fs.readFileSync('f.yaml','utf8'));console.log('valid')}catch(e){console.error(e.message)}"

Frequently Asked Questions

What is a YAML validator?

A YAML validator checks whether a YAML document follows the YAML specification — correct indentation (spaces only), properly formed mappings and sequences, valid scalar types, and no structural errors. It reports the exact line and column of any syntax error.

What are the most common YAML errors?

Tab characters used for indentation (YAML requires spaces), inconsistent indentation levels, missing colons after mapping keys, and duplicate keys. The most subtle errors come from YAML 1.1 parsers silently converting bare values like yes, no, on, off to booleans.

What are YAML 1.1 coercion risks?

YAML 1.1 parsers (PyYAML, Docker Compose using go-yaml v2, GitHub Actions) silently convert bare yes, no, on, off to booleans, and sexagesimal values like 22:30 to integers (1350). YAML 1.2 parsers (js-yaml v5+, go-yaml v3, ruamel.yaml) do not. Quote these values to be safe.

Is my YAML data sent to a server?

No. All validation runs entirely in your browser using js-yaml. Your data never leaves your machine.

Why does YAML require spaces instead of tabs?

The YAML specification explicitly forbids tabs for indentation because different editors interpret tab widths differently. Using spaces guarantees consistent structure. A YAML parser will throw an error if it encounters a tab used for indentation.

How do I validate YAML in Node.js?

Use js-yaml: yaml.load(input) inside a try/catch. The error message includes the line number. js-yaml v5+ implements YAML 1.2 and does not silently coerce yes/no/on/off to booleans.

How do I validate YAML in Python?

Use yaml.safe_load(text) inside a try/except catching yaml.YAMLError. Note that PyYAML implements YAML 1.1 and will silently coerce yes/no/on/off to booleans. For YAML 1.2 behaviour, use ruamel.yaml instead.

What is the difference between YAML validation and JSON validation?

YAML validation checks for correct YAML syntax — indentation, mapping structure, scalar types. JSON validation checks for correct JSON syntax — braces, quotes, commas. YAML is a superset of JSON (valid JSON is valid YAML 1.2), but YAML additionally supports anchors, aliases, multi-line strings, and type coercion.

Related Tools

Other free developer tools available on DevFormatter.