Libraries implementing YAML
YAML processors are available in many languages, some even in bash, although probably not very complete.
Because of the history of YAML the implementations differ a lot.
- There are three versions, 1.0, 1.1 and 1.2.
- The specification for version 1.1 had problems like ambiguity
- 1.2 was created to solve the problems with 1.1, but already many implementations had been created and were never updated.
- There was no test suite until 2016
Library Overview
This table is work in progress. More information will be following.
Language | Library | Syntax | Uses YAML Test Suite |
YAML Runtimes |
|
---|---|---|---|---|---|
1.2 | 1.1 | ||||
C | libfyaml | ✓ | (✓) | ✓ | ✓ |
C | libyaml | ~ | ~ | ✓ | ✓ |
C# | YamlDotNet | ✓ | n/a | ✓ | ✓ |
C++ | yaml-cpp | ~ | n/a | n/a | ✓ |
Haskell | HsYAML | ✓ | n/a | ✓ | ✓ |
Java | SnakeYAML | n/a | ~ | n/a | ✓ |
Javascript | js-yaml | ~ | ~ | n/a | ✓ |
Javascript | yaml | ✓ | (✓) | ✓ | ✓ |
Perl | YAML::PP | ~ | ~ | ✓ | ✓ |
Perl/XS | YAML::XS (libyaml) | ~ | ~ | n/a | ✓ |
Python | PyYAML | ~ | ~ | n/a | ✓ |
Python | ruamel.yaml | ~ | ~ | n/a | ✓ |
Ruby | psych | n/a | ~ | n/a | ✓ |
Features not implemented in every Library
libyaml and PyYAML have been implemented by Kirill Simonov in 2006. Many other implementations were ported from them or use libyaml bindings.
There were a number of features where the author diverged from the spec.
While that might have been a good idea, the YAML Spec itself did not follow that, and so some libraries support features, while implementations originating from libyaml do not.
This is a (still very incomplete) list of features that you should avoid to be compatible to as much libraries as pssible.
Most of them aren't relevant in the real world.
Empty Keys
--- key: value : value2
In YAML 1.2, by default, this is basically the same as:
--- key: value null: value2
Depending on the programming language, the key will often be converted to the empty string.
Having empty strings or null as keys is rare, and if you need them, you should explicitly write what you want:
--- key: value null: value2 --- key: value '': value2
Allowed characters in Aliases/Anchors
The spec says that pretty much every character is allowed:
- &😁 unicode anchor - &:@*!$"<foo> WTF?
libyaml originated libraries usually only support [A-Za-z0-9-]:
- &Valid-anchor1 simple