Unable to parse YAML: mapping values are not allowed here

The error message Unable to parse YAML: mapping values are not allowed here usually occurs when there is a syntax error in the YAML file.

To resolve this issue, we can consider following the steps below:

Check syntax and indentation

YAML relies on proper indentation and syntax. We need to ensure that our YAML file follows the correct syntax rules. Let's see some of the rules that are necessary to incorporate in our YAML file:

Correct indentation

We need to use spaces for indentation instead of tabs. Giving an indentation of two or four spaces is preferable, but we must ensure consistent indentation levels. Below, we can see that the YAML file is incorrect at line 3 due to the wrong indentation of subkey2:

key1:
subkey1: value1
subkey2: value2

We resolve the error by correctly indenting subkey2 with two spaces:

key1:
subkey1: value1
subkey2: value2

Missing colon (:)

We must ensure that key-value pairs are properly formatted with a colon (:) separating the key and value. We can see in the code below that the colon (:) is missing after key2, which will cause an error:

key1: value1
key2
subkey1: value2

We correct the error by adding the colon (:) as shown below:

key1: value1
key2:
subkey1: value2

Extra punctuation marks

We must ensure that we do not add extra colons, commas, or punctuation marks to the file. Below we see a YAML file that causes errors at:

  • Line 1: Due to an unnecessary colon after value1.

  • Line 4: Due to an unnecessary comma after subkey2 instead of a colon.

  • Line 8: Due to an unnecessary comma after item3 instead of a colon.

key1: value1:
key2:
subkey1: subvalue1
subkey2, subvalue2
key3:
- item1
- item2
- item3,

We can see below that the file is corrected after resolving the errors mentioned above:

key1: value1
key2:
subkey1: subvalue1
subkey2: subvalue2
key3:
- item1
- item2
- item3

List formatting

We need to properly format each list item in a sequence (list) with a dash (-) followed by a space. We can see below that in line 6, the list item item4 is not correctly formatted:

key1:
- item1
- item2
key2:
- item3
item4

We correct the error by adding a dash (-) and a space before item, as shown below:

key1:
- item1
- item2
key2:
- item3
- item4

Strange Unicode characters

We must remove strange Unicode characters in our YAML file, which may cause the mapping values are not allowed here error. Most of the strange Unicode characters can be removed by an eyeball, but there are spaces other than the regular space that may cause an error. There are multiple spaces like U+2009(thin space), U+200A (hair space), and U+200B (zero width space). To remove these spaces, we can download the Gremlins extension in VS Code that reveals the invisible whitespaces and other Unicode characters.

Conclusion

Once we ensure that our YAML file is correctly structured according to the rules mentioned above, our error message Unable to parse YAML: mapping values are not allowed here will be resolved. If we cannot find any syntax issues, use an online YAML validator and correct the problems it identifies.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved