Allowed characters in map key identifier in YAML?

According to the YAML 1.2 specification simply advises using printable characters with explicit control characters being excluded (see here):

In constructing key names, characters the YAML spec. uses to denote syntax or special meaning need to be avoided (e.g. '#' denotes comment, '>' denotes folding, '-' denotes list, etc.).

Essentially, you are left to the relative coding conventions (restrictions) by whatever code (parser/tool implementation) that needs to consume your YAML document. The more you stick with alphanumerics the better; it has simply been our experience that the underscore has worked with most tooling we have encountered.

It has been a shared practice with others we work with to convert the period character '.' to an underscore character '_' when mapping namespace syntax that uses periods to YAML. Some people have similarly used hyphens successfully, but we have seen it misconstrued in some implementations.


Any character (if properly quoted by either single quotes 'example' or double quotes "example"). Please be aware that the key does not have to be a scalar ('example'). It can be a list or a map.