This. I find YAML to be the least offensive option for configuration and one of the worst for serialization.
I might be misinformed, but I find it absurd that in 2021 we still don't have a default, universally available tool that supports the basic table stakes without headache:
1. core data types (number, string, etc)
2. lists, maps, and arbitrary nesting
3. comments
4. multiline strings
5. is acceptably readable
6. Just Works everywhere
YAML does get 1-5 right (specifically 3 and 4 that JSON doesn't and IMO better in 5). But then it adds a ton of complexity that has left us without a standard, safe, and sane parser implementation: anchors and references (& and *) , casting (via !!), custom data types (via !), loads of other things I don't understand.
also you can have multiple instances of yaml trees in one file, each one separated with -- . I think this makes it very confusing if used as a configuration language (they like to use yaml for configuration in kubernetes)
might not be as "common" but it has good implementations for many languages.
cat cfg.json | sed -e 's/\s*#.*$//g' | jq .
Allowing multiple lines is more complicated, can't do that with regex alone.If anybody short of a standards body tries to expand the spec, you lose out on most of that.
And without comments or optional quoted keys single quotes or trailing commas, which makes editing by hand more work and IMO less readable.
TOML is pretty close as well.
Just use TOML for configuration instead.
Hey, it's still better than having to write the configuration in Erlang like you had to before.
JSON's lack of support for trailing commas messes up diffs.
0. Looks essentially the same as JSON
1. Core data types, and customizable data types can be added easily.
2. Arrays, Objects, and arbitrary nesting.
3. Comments ( both /* */ and // format )
4. Multiline strings ( by default; carriage returns are no problem within strings )
5. It is JSON with relaxed restrictions and slight addition for actual named types.
6. I've written C, Perl, and Golang implementations so far.
YAML ends up being a powerfully declarative model [2] for the state of a data structure, rather than a straight representation, ironically often enough being used in turn for an imperative model like in Ansible [3]. Definitely friendlier than JSON. But personally, I really like YAML because it lets me compose using a traits/mixins-like model using & and *, which allows for verbose, structured configuration inputs but concise configuration files.
docker-compose YAML files extension fields [4], imo, are a great example of this type of model in action. When you leave this much pre-deserialization flexibility in your configuration representation, it makes building cool stuff like docker-compose ECS support x-aws-* extension keys [5] and other plugin system-type capabilities much more straightforward than, for example, adding a new language feature to HCL.
[1]: https://github.com/google/skylark
[2]: https://en.wikipedia.org/wiki/YAML#Advanced_components
[3]: https://docs.ansible.com/ansible/latest/user_guide/playbooks...
[4]: https://docs.docker.com/compose/compose-file/compose-file-v3...
[5]: https://docs.docker.com/cloud/ecs-integration/#rolling-updat...
I think YAML is even worse as a serialization format than a configuration format. It has too many ambiguities, implementations are too inconsistent, and many implementations are insecure by default with untrusted input.
> Using a good custom designed configuration file format instead of trying to shove things through the narrow pipe of YAML means that you have one integrated syntax that can be designed to be more readable, more expressive, and much easier to write.
I won't say a custom configuration is never the right thing to do, but I do think it rarely is. Writing a good custom configuration language is very difficult to get right, not to mention you also need syntax highlighting and other editor support for the editors your users use, libraries for popular languages so that other programs can read and write the configuration, etc. If you need something this complicated, I'd reach for using an embedded scripting language like lua (or possibly JavaScript or python) before writing a new format from scratch.