'How to fix "mapping values are not allowed in this context " error in yaml file?

I've browsed similar questions and believe i've applied all that i've been able to glean from answers.

I have a .yml file where as far as I can tell each element is formatted identically. And yet according to YamlLint.com

(<unknown>): mapping values are not allowed in this context at line 119 column 16

In this case, line 119 is the line containing the second instance the word "transitions" below. That I can tell each element is formatted identically. Am I missing something here?

  landingPage:
    include: false
    transitions:
      -
        condition:location
        nextState:location

  location:
    include:false
    transitions:
      -
        condition:excluded
        nextState:excluded

  excluded:
    include:false
    transitions:
      -
        condition:excluded
        nextState: excluded
      -
        condition:age
        nextState:age



Solution 1:[1]

You cannot have a multiline plain scalar, such as your include:false transitions be the key to a mapping, that is why you get the mapping values not allowed in this context error.

Either you forgot that you have to have a space after the value indicator (:), and you meant to do:

        include: false
        transitions:

or you need to quote your multi-line scalar:

        'include:false
        transitions':

or you need to put that plain scalar on one line:

        include:false transitions:

please note that some libraries do not allow value indicators in a plain scalar at all, even if they are not followed by space

Solution 2:[2]

we need to use space before ":" Then it will excecute check the yaml script in below http://www.yamllint.com/

Solution 3:[3]

I fixed this for myself by simply realizing I had indented a line too far, and un-indenting it.

Solution 4:[4]

For me the problem was a unicode '-' from a cut and paste. Visualy it looked OK, but the character was 'EN DASH' (U+2013) instead of 'HYPHEN MINUS' (U+002D)

Solution 5:[5]

There are couple of issues in the yaml file, with yaml files it gets messy, fortunately it can be identified easily with tools like yaml lint

Install it

npm install -g yaml-lint

Here is how you can validate

E:\githubRepos\prometheus-sql-exporter-usage\etc>yamllint prometheus.yaml
? YAML Lint successful.

Solution 6:[6]

In mine case it was the space after the : in a value:

query-url: https://blabla.com/blabla?label=blabla: blabla

To fix:

query-url: https://blabla.com/blabla?label=blabla:%20blabla

Or:

query-url: "https://blabla.com/blabla?label=blabla: blabla"

Solution 7:[7]

If you are using powershell and have copied the cat command, it won't work properly (I'm guessing it is encoding the content in some way). Instead of using "$(cat file.yaml)" you should use $(Get-Content file.yaml -Raw) without the quotes.

Really annoying!

Solution 8:[8]

In my case if was some odd disappearing of the initial formatting of the initial chart that was copied in Intellij Idea. It was possible to gfigure out with text-compare tool only:

enter image description here

So, when you do your copy and paste in your IDE, please double check is what you have copied is exactly what you paste, aren't some additional spaces were added.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anthon
Solution 2 NMNS chaitanya
Solution 3 temporary_user_name
Solution 4 Neil Darach
Solution 5 craftsmannadeem
Solution 6 Andry
Solution 7 Luke Briner
Solution 8