DataSwitch Pro Private, in-browser data converter

Common YAML Errors and How to Fix Them

By the DataSwitch Pro team · · 4 min read

Quick answer

Most YAML errors come from indentation (mixing tabs and spaces, or uneven spaces between sibling keys), a missing space after a colon, an unquoted value that contains : or starts with a special character, and values YAML types unexpectedly, such as no, 1.10 or 0123. Read the line and column in the error, fix that spot, and convert the file to JSON with a YAML to JSON converter to confirm the structure is what you meant.

YAML is pleasant to read, but its reliance on whitespace means one stray space can break a deployment. Parsers point to a line and column; the trick is knowing what each message usually means.

1. “bad indentation of a mapping entry”

A key is indented differently from its siblings, so the parser cannot tell which parent it belongs to.

Broken

server:
  host: example.com
   port: 8080

Fixed

server:
  host: example.com
  port: 8080

Keys at the same level must start in exactly the same column. Configure your editor to show whitespace, and use two spaces per level consistently.

2. Tabs: “found character that cannot start any token”

YAML forbids tab characters for indentation. A tab copied from another file or inserted by the editor triggers this error. Replace tabs with spaces; most editors have a “convert indentation to spaces” command.

3. “mapping values are not allowed here”

A value contains a colon followed by a space, so YAML thinks a new key starts:

Broken → fixed

title: Note: restart required
title: "Note: restart required"

The same error appears when a space is missing after a colon in the line above (name:api), which turns the whole line into a plain string.

4. Values starting with special characters

A value cannot start unquoted with @ or a backtick, and values starting with *, &, !, %, {, [ or | have special meanings. Quote them: password: "*secret", pattern: "[a-z]+". A # preceded by a space starts a comment, so color: #fff silently becomes null — quote it as "#fff".

5. “duplicated mapping key”

The same key appears twice at one level. Some parsers reject this; others keep the last value without warning, which can hide a configuration mistake. Merge the two entries.

6. List items at the wrong level

Broken

steps:
- run: npm ci
  - run: npm test

Every - of the same list must be aligned. Both styles are valid — dashes aligned with the parent key, or indented under it — but not a mix within one list.

7. Values that parse as the wrong type

These do not raise errors, which makes them more dangerous:

Quote any value whose type matters. Converting the file to JSON shows immediately how each value was read.

8. Multi-line strings

Use a block scalar instead of breaking a long value across lines by hand: | keeps line breaks (for scripts), > folds them into spaces (for long text). Add - (|-) to drop the final line break.

A reliable debugging routine

  1. Go to the line and column in the error, and also check the line above it.
  2. Turn on visible whitespace in your editor to spot tabs and uneven spaces.
  3. Paste the file into the YAML to JSON converter: if it converts, compare the JSON with what you expected; if not, it shows the error position.
  4. For tool-specific files (GitHub Actions, Kubernetes), run that tool's own linter, since valid YAML can still be an invalid configuration.

For background on when YAML is the right choice at all, see YAML vs JSON.

Try it on your own file. Free, private, and processed in your browser.

Frequently asked questions

Can I use tabs in YAML?

Not for indentation. Tabs are allowed inside quoted strings, but indentation must use spaces.

How many spaces should YAML indentation use?

Any consistent number works; two spaces is the most common convention.

Why does “on:” work in GitHub Actions?

GitHub's parser treats on as a key string. Other YAML 1.1 parsers may read it as true, so quote it in shared tooling.

Does converting to JSON fix YAML errors?

No, but it shows exactly how the parser understood the file, which makes structural and type mistakes easy to spot.

More guides