5 ms·
I have a project with fairly complex YAML config files. YAML quickly gets cranky and brittle, there are too many ways to do everything, and it's very challengi
by fake-name 9y ago
I have a project with fairly complex YAML config files.
YAML 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.
- exogen 9y agoCompletely agreed. For me, writing YAML always feels like a guessing game. 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.
- simcop2387 9y agoTake a look at TOML next time, very simple syntax and a lot of libraries coming around. I've been using it in every new project I start when I end up wanting configuration. https://github.com/toml-lang/toml https://github.com/toml-lang/toml
- gnur 9y agoIf yaml ever gets too cranky, just use JSON in your yaml document. 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"}]}
- bmn__ 9y ago> yaml is a superset of json, any valid json is valid yaml as well This is wrong. http://p3rl.org/JSON::XS#JSON-and-YAML http://p3rl.org/JSON::XS#JSON-and-YAML