Cryonel

YAML Bad Indentation Error, Explained

Unlike JSON, YAML uses whitespace itself to express structure — so indentation isn't cosmetic, it's syntax. A single misplaced space breaks parsing.

What triggers it

How to fix it

Configure your editor to insert spaces, not tabs, on Enter/Tab (most YAML-aware editors do this by default when they detect a .yml/.yaml extension). Pick one indent width (2 spaces is the near-universal convention) and stick to it throughout the file. When in doubt about a value containing a colon, quote it.

If you just need to convert between formats rather than hand-write YAML, the JSON ⇄ YAML Converter lets you build the structure as JSON — where indentation is not significant — and get valid YAML out.

Confirm the parsed structure

A file can become syntactically valid after re-indenting and still describe the wrong object. Compare the parsed JSON form before and after the edit, especially for lists of mappings and nested configuration blocks. A single misplaced dash can turn one object into several items, while a key moved two spaces can attach to the wrong parent.

For CI, parse every YAML file with the same library and YAML version used by production, then validate the resulting object against a schema when one exists. Quote ambiguous scalar values such as dates, booleans, and values containing : when they must remain strings. This catches semantic changes that a basic syntax check cannot see.

Frequently Asked Questions

Can indentation use tabs?

No. YAML indentation uses spaces.

How many spaces should I use?

Two is common, but consistent sibling alignment matters more than a specific width.

Why can repaired YAML still be wrong?

Indentation controls nesting, so a syntactic repair can change which parent owns a value.

Related Tools and Guides