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: productionFixed
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: 80Fixed
server:
host: localhost
ports: 80Fix: 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: valueFixed
description: This is a note
extra: valueFix: 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-teamFixed
maintainer: "@platform-team"Fix: Quote the value.
Find it fast
- 1.Check the reported line for a
:inside the value and quote the value if there is one. - 2.Count the spaces on the reported line and on its siblings; make them identical.
- 3.Check whether the key above the reported line already has a value on the same line.
- 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
| Parser | Message |
|---|---|
| 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 loader | mapping 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 validator | A 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
“mapping values are not allowed in this context”
The parser hit a colon followed by a space in the middle of a value, where YAML only allows a colon after a key. Quote the value if the colon is part of it, or fix the line above if the parser was still reading it.
Read the fix“did not find expected key”
The parser was inside a mapping and expected either another key at the same indentation or the end of the block, but found something that cannot be a key: a line dedented by the wrong amount, a list dash, or an invisible character. Line up the indentation of the line it reports with its siblings.
Read the fix“found character that cannot start any token”
The scanner reached the start of a new token and found a character no YAML token may begin with. In almost every case it is a tab used for indentation. The other two are a value beginning with @ or a backtick, which YAML reserves.
Read the fixAll 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.
YAML to JSON
Convert YAML into formatted or minified JSON, with errors pinned to the exact line.
OpenJSON to YAML
Turn JSON back into readable YAML, with control over indentation and key order.
OpenYAML Validator
Check YAML for syntax errors and get a plain-English explanation of what went wrong.
OpenYAML Formatter
Reformat messy YAML with consistent indentation and keep your comments intact.
Open