YAML allows the node content to be omitted in many cases. Nodes with empty content are interpreted as if they were plain scalars with an empty value. Such nodes are commonly resolved to a “null” value.
I tried different YAML parsers (e.g. yq, pyyaml and Go's yaml/v2 package, which is based on LibYYAML) and it seems as if most resolve empty node values to null, whereas SharpYaml seems indeed to be a notable exception when it comes to handling empty node values.
What's my problem?
I just recently stumbled across some weird behavior in bicep, which uses SharpYaml under the hood for it's
loadYamlContent()
function.Parsing a YAML file with empty node contents yields empty strings instead of null values, which seems wrong from what I can tell.
Example
The following YAML document
is parsed as:
I expected the value of
nested1
to benull
as well, though.Excerpt from the YAML 1.2.2 specification:
Example 7.3: Completely Empty Flow Nodes seems to further clarify how empty node content should be resolved.
Conclusion
I tried different YAML parsers (e.g. yq, pyyaml and Go's yaml/v2 package, which is based on LibYYAML) and it seems as if most resolve empty node values to
null
, whereas SharpYaml seems indeed to be a notable exception when it comes to handling empty node values.Links