Skip to main content

YAML error: mapping values are not allowed here

Paste your YAML and click Validate to find the line with the extra colon

14
Loading editor…

What the error means

In YAML a colon followed by a space turns the text before it into a key. A plain, unquoted value can still contain a colon when it is not followed by a space, as in http://example.com:8080. When the parser finds a second ": " on the same line, or a key nested under a value that already has one, it cannot make a second mapping there and raises "mapping values are not allowed here", with the line and column of the extra colon.

JavaScript's js-yaml, which the validator above uses, words the same problems as "bad indentation of a mapping entry". The reported line and column are the same.

Causes and fixes

Wording below is PyYAML's. Each example fails the same way in both parsers.

Colon and space inside an unquoted value

Error: mapping values are not allowed here in "<unicode string>", line 1, column 12

Invalid

title: Note: draft

Fixed

title: "Note: draft"

Put the value in quotes, or use a block scalar (title: | on its own line, then the text indented below it). Single or double quotes both work.

Command or message with a colon

Error: mapping values are not allowed here in "<unicode string>", line 1, column 16

Invalid

run: echo hello: world

Fixed

run: 'echo hello: world'

Shell commands in CI files such as GitHub Actions or GitLab CI often contain colons. Quote the whole command. A quote inside the value is not enough: command: echo "a: b" still fails, because the value does not start with a quote.

Nested key indented under a value

Error: mapping values are not allowed here in "<unicode string>", line 2, column 8

Invalid

name: web
  image: nginx

Fixed

name: web
image: nginx

name already has the value web, so image cannot be nested under it. Align the keys, or move the value onto its own mapping: put name: on a line by itself and indent both lines below it.

Two keys on one list line

Error: mapping values are not allowed here in "<unicode string>", line 1, column 10

Invalid

- name: x: y

Fixed

- name: 'x: y'

The list item is a mapping with the key name, and the value x: y contains a second colon. Quote the value.

PyYAML (and so Ansible, Home Assistant and many Python tools) raises this when a colon appears where YAML does not allow a new key. The cause is nearly always an unquoted value that contains a colon followed by a space, or a nested key indented under a value.

Frequently Asked Questions

Why is a URL fine but 'Note: draft' is not?

A colon only counts as a key separator when a space (or the end of the line) follows it. In http://example.com:8080 no colon is followed by a space, so the whole thing is one plain value.

Single or double quotes?

Both make the value a string. Double quotes allow escape sequences such as \n; single quotes take everything literally, and a single quote inside is written twice ('').

Does indentation cause this error too?

Yes. Indenting a key under a line that already has a value is the other common cause. Also check that you used spaces and not tabs, which YAML forbids for indentation.

Why does this validator show a different message?

It uses the js-yaml parser, which words this as 'bad indentation of a mapping entry'. The line and column point at the same place as PyYAML's message.

Have suggestions or feedback? We're constantly improving FormatChamp based on your comments.