fjordtools / Errors / YAML: mapping values not allowed

mapping values are not allowed here

The parser found a colon followed by a space in a place where a new key cannot start. Usually a plain text value contains a colon, such as a title with a note, so the value must be put in quotes. The other common cause is a line indented wrongly, so it looks like part of the line above.

Fjordtools team · Seen in PyYAML · Published · 1 min read

How browsers word it

PyYAMLyaml.scanner.ScannerError: mapping values are not allowed here
js-yamlYAMLException: bad indentation of a mapping entry
Go (yaml.v3)yaml: mapping values are not allowed in this context

Common causes

  1. A colon inside a plain value

    In plain text a colon followed by a space starts a new key. Put the value in quotes.

    Input

    title: Note: read this

    YAML JSON TOML says

    Line 1, column 8: A key can't start on the same line as another key
  2. Two keys on one line

    A YAML mapping has one key per line.

    Input

    a: b: c

    YAML JSON TOML says

    Line 1, column 4: A key can't start on the same line as another key
  3. A wrongly indented line

    A line with more spaces than the one above it looks like part of that value.

    Input

    key: value
      bad: x

    YAML JSON TOML says

    Line 2, column 6: Unexpected ':'. Is a key indented wrongly?
  4. The same value in quotes

    Quotes make the colon part of the text.

    Input

    title: "Note: read this"

    YAML JSON TOML says

    {"title": "Note: read this"}

How to fix it

  1. Put values that contain a colon followed by a space, a hash sign or special characters in quotes.
  2. Give every key its own line, and indent child keys with the same number of spaces.
  3. Use spaces, not tabs, for indentation.
  4. Paste the file into the YAML converter: it names the line and column of the problem.

Related tool

More error explainers are coming

See all errors.