YAML Indentation Error – Find and Fix Invalid Indentation

Local only

YAML uses indentation to define nesting. A line shifted to the wrong level can change the structure or make the document impossible to parse.

34 chars · 3 lines

Waiting for input

Loading YAML parser…

YAML indentation troubleshooting

How to find and fix a YAML indentation error

Paste the failing YAML into the validator above to check the exact document rather than guessing from how it looks in an editor. The preloaded sample shifts port one space deeper than the surrounding mapping, which creates a nesting level that does not belong there. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • YAML 1.2 parser validation
  • Duplicate mapping key detection
  • Preloaded broken YAML example
  • Readable parser feedback
  • .yaml and .yml file import
  • Browser-local processing

Steps

  1. Paste the exact YAML that fails into the validator.
  2. Compare the reported line with the indentation level of its parent mapping or sequence.
  3. Move the line to the intended level using spaces, then validate the complete document again.

Why YAML indentation is part of the data structure

Unlike formats that use braces around every nested object, block-style YAML uses leading spaces to show which values belong together. Sibling keys need the same indentation and child content must be indented beyond its parent.

  • Keep sibling mapping keys aligned.
  • Indent nested mappings and sequences consistently.
  • Do not fix only the reported line without checking the surrounding block.

Fix the intended hierarchy, not just the parser message

A parser can tell you that the indentation is impossible, but it cannot know whether a key should be a sibling, a child, or a new top-level section. Compare the corrected YAML with the configuration structure your application expects.

YAML mapping indentation example

The port key has one extra leading space and should align with name.

Invalid YAML

service:
  name: api
   port: 8080

Corrected YAML

service:
  name: api
  port: 8080

Common questions

Frequently asked questions

How many spaces should YAML indentation use?

YAML does not require one universal width, but indentation must be consistent for each block. Two spaces is a common convention for configuration files.

Can valid YAML use different indentation widths?

Different nested levels can be represented with spaces as long as the structure is unambiguous, but mixing widths within sibling blocks is difficult to review and often causes mistakes.

Does the validator upload my YAML?

No. YAML parsing runs locally in your browser.

Debugging a specific YAML issue? Browse YAML troubleshooting.