Skip to content

YAML error

“bad indentation of a mapping entry”

js-yaml reports several unrelated mistakes under this one message: an unquoted value containing a colon, a sibling key indented differently, a key nested under a key that already has a value, or a value starting with @ or a backtick. Check the reported line for each, in that order.

By yamltojsonfree · Published · Updated

What the parser is telling you

js-yaml does not distinguish between the reasons a mapping entry can land in the wrong place; whenever it finds a key: pair at a column it did not expect, it prints this. That makes the message less precise than libyaml’s, which splits the same cases into “mapping values are not allowed in this context” and “did not find expected key”, but the fix is always one of the four below.

The converter on this site uses js-yaml and translates this message into the specific cause. For unclosed brackets and quotes, which js-yaml reports as “deficient indentation” many lines later, it names the delimiter and the line where it was opened.

Who prints this message

js-yaml prints this, so it appears in Node tools, in most browser-based YAML converters including the one on this site, and in static site generators built on Node. The sibling message “bad indentation of a sequence entry” is the same problem for a - list.

The causes, with fixes

Broken YAML on the left, the corrected form on the right. The fix under each pair is the one that applies to that cause.

A colon inside an unquoted value

The second : on the line starts what looks like a nested mapping inside a value.

Broken

title: Deploy: production

Fixed

title: "Deploy: production"

Fix: Quote the value.

Sibling keys indented differently

Two spaces on one line and three on the next end the block early, and the third line becomes a mapping entry at a column nothing is open at.

Broken

server:
  host: localhost
   ports: 80

Fixed

server:
  host: localhost
  ports: 80

Fix: This is what linters call inconsistent indentation. The YAML formatter on this site rewrites every level to the same width and keeps your comments.

A key nested under a key that already has a value

description has a scalar value, so nothing can be nested beneath it; the indented extra is read as a continuation of the text and then fails on its colon.

Broken

description: This is a note
  extra: value

Fixed

description: This is a note
extra: value

Fix: Either dedent the second key to make it a sibling, or remove the value from the parent so it can hold children.

A value starting with @ or a backtick

YAML reserves both characters at the start of a plain value; js-yaml reports the resulting confusion as an indentation problem.

Broken

maintainer: @platform-team

Fixed

maintainer: "@platform-team"

Fix: Quote the value.

Find it fast

  1. 1.Check the reported line for a : inside the value and quote the value if there is one.
  2. 2.Count the spaces on the reported line and on its siblings; make them identical.
  3. 3.Check whether the key above the reported line already has a value on the same line.
  4. 4.Paste the document into the converter or validator on this site; the same parser is used, and the message is translated into the specific cause.

The same error in other parsers

ParserMessage
js-yaml (Node, most browser tools)bad indentation of a mapping entry
libyaml, go-yaml (kubectl, Helm, Compose)mapping values are not allowed in this context, or did not find expected key
PyYAML, pure-Python loadermapping values are not allowed here, or expected <block end>, but found ...
yaml (npm)Nested mappings are not allowed in compact mappings, or All mapping items must start at the same column
This site’s validatorA mapping entry isn’t lined up with the block it belongs to.

Frequently asked questions

What is the difference from “bad indentation of a sequence entry”?

The sequence version is the same problem for a list: a dash that is not at the same column as the other dashes in its list, or a list item nested under a key that already has a value. Line the dashes up, and make sure the key above the list has no value on its own line.

Why does js-yaml report the error on a later line than the mistake?

A plain value can continue onto the next lines, so js-yaml is often still reading the previous value when it reaches the line it reports. For unclosed brackets and quotes it can be dozens of lines later, and the message becomes “deficient indentation”. Start from the reported line and read upward.

Is this the same as “inconsistent indentation”?

Usually. Linters and editors describe uneven sibling indentation that way, and js-yaml reports it as bad indentation of a mapping entry. The formatter on this site rewrites indentation to a consistent width while keeping comments, which fixes the whole class at once.

Related errors

All six underlying mistakes, ordered by cause rather than by message, are in the guide Common YAML errors and how to fix them. Every one of them is caught with the exact line and a suggested fix by the free tools below; nothing is uploaded.