Hacker News new | ask | show | jobs
by laputan_machine 1464 days ago
I prefer YAML to JSON for our infra. I know some people do not like the whitespace.

What do you prefer?

2 comments

JSON:

* doesn't encode Norway to false;

* most formatters for JSON are deterministic.

* doesn't deserialize into arbitrary objects;

YAML, in in constrast...

* YAML is insecure by default and will deserialize into arbitrary objects;

* YAML knows that there's no such thing as wall clock time, there's only number of seconds since midnight;

* YAML has 22 ways of writing true or false, and the parser will silently replace your "strings" with false.

* There are 63 ways of writing multi-line strings;

* A truncated YAML file is still a "valid" YAML file.

https://noyaml.com/

IMO the solution to YAML-as-config is a strict subset of YAML.

JSON is one strict subset, but one that makes smart trade-offs for strictness and machines like error detection and syntax-typed types.

We decided on a different subset of YAML for our users that were modifying config by hand (even more strict than StrictYAML). Some of the biggest features of YAML are that there is no syntax typing, and collection syntax is simple (e.g. also true for JSON, false for TOML).

For example, a string and a number look the same. This seems bad to us developers at first, but the user doesn't have to waste 20 min chasing down an unmatched quote when modifying config in a <textarea>. Beyond that, it's the same amount of work as making sure the JSON is `"age": 20` instead of `"age": "20"`, one just has noisier syntax.

I think the StrictYAML docs have a great breakdown of the advantages: https://hitchdev.com/strictyaml/why-not/

We decided against TOML because nesting is too confusing. https://github.com/toml-lang/toml/issues/846

Declarative code. CSS is better than YAML for describing a desired state.