Zac Romero
Zac Romero

Reputation: 406

Is it valid YAML to have a flow mapping (or sequence) with the closing character at the same indentation as the parent key?

As an example, consider the following YAML:

foo: {
   "a": "b"
}

notice how the final '}' character is on the same indentation as the key "foo". Is this considered valid YAML?

A close reading into the specification as well as testing it out on the "YPaste Interactive Parser" link posted on the official YAML site leads me to believe that it is not valid, but most parser will accept this (it is also intuitive that this be valid).

Note: The following is definitely a valid YAML document as the final '}' has an indentation:

foo: {
   "a": "b"
 }

Upvotes: 0

Views: 77

Answers (1)

Zac Romero
Zac Romero

Reputation: 406

This is not valid yaml despite multiple parsers accepting it.

Running this through the perl parser YAML::PP which has an almost perfect parse score errors on this results in a parse failure. This document also explicitly states that such YAML is incorrect.

Upvotes: 1

Related Questions