YAML feels to me like the creation of a person who has never fought with a makefile that imported another makefile that had an extra tab on line 9432: not quite true hell, but a few hours of trying to figure out WHY things aren't working right you would be hard pressed to tell the difference.
YAML says there's a world of difference between
- flag1
- option2
and -flag1
-option2
but for a human who just wants their thing to work, that's inscrutable, but in JSON, they become [
"flag1",
"config2"
]
and "-flag1 -config2"
respectively.Personally, live python as config is my preference, followed by YAML because comments, but YAML isn't perfect.
If the options are right next to each other it's clear there's a misalignment:
- option1
-option2
won't work, but - option1
# if there is a huge explanatory# multi-line comment
# as is sometimes seen in config
# files, sometimes it can be hard
# to see the misalignment.
- option2YAML quickly gets cranky and brittle, there are too many ways to do everything, and it's very challenging to easily debug some of the syntax errors. If I had to do it over again, I'd probably go with json over yaml.
With JSON, I can have my text editor do the validation before I even save. That kind of tooling just doesn't exist for YAML.
When I first encountered an ESLint config written in YAML, for example, it took me like a dozen tries (no exaggeration) to successfully convert a
[2, "always"]
type value into a more advanced [2, { "options": blah, "foo": bar }]
value. The ways that intuitively seemed like they definitely should have worked, didn't work, and I consider myself a competent programmer.I came to dislike it even more once I found out it had features like &anchors, <<:, etc. Not only do I find the syntax repulsive, but having custom user-named sections whose identifiers aren't actually significant and don't end up in the parsed structure is probably wasting a ton of people's time as they Google documentation for config section names that the consuming program doesn't actually understand because they don't really exist (they were just named at the author's whimsy).
It's not worth it. Use JSON, or possibly JSON5.
Since yaml is a superset of json, any valid json is valid yaml as well. This allows you to combine the two in very convenient ways:
---
test:
obj: {"solution": ["in", "the", "list", {"everything: "is possible"}]}This is wrong.
I rather just start with a real Python or JavaScript object literal in my source, and when it grows, move it to a new file, and run over it with a lenient JSON parser.