logoalt Hacker News

yashap • 12/08/2024 • 5 replies • view on HN

I’m a fan of JSON5. A common criticism is “we’ve already got YAML for human readable config with comments,” but IMO YAML’s readability sucks, it’s too hard to tell what’s an object and what’s an array at a glance (at least, with the way it’s often written).

When dealing with large YAML files, I find myself frequently popping them into online “YAML to JSON” tools to actually figure out WTF is going on. JSON5 is much easier to read, at least for me.


Replies

stackskipton • 12/08/2024

Those two criticisms of YAML are at bottom of my list. Space as delimiter and lack of strict typing is what screws me over on daily basis as SRE.

➕ show 2 replies
couscouspie • 12/08/2024

Just in case you didn't know: With https://github.com/mikefarah/yq you can just immediately translate YAMLs like

  yq some.yaml -o json
➕ show 1 reply
AdieuToLogic • 12/08/2024

> When dealing with large YAML files, I find myself frequently popping them into online “YAML to JSON” tools to actually figure out WTF is going on.

YAML is a strict superset of JSON, so defining the former in the syntax of the latter is fully supported by the spec. Perhaps not by every YAML library, to be sure, but those which do not are not conformant. From the YAML spec[0]:

  The YAML 1.23 specification was published in 2009. Its 
  primary focus was making YAML a strict superset of JSON.
0 - https://yaml.org/spec/1.2.2/
➕ show 2 replies
marcyb5st • 12/08/2024

What's your take on prototxt files? In my opinion it is the most readable format since you don't need square brackets for repeated fields/arrays.

Additionally plugins let you link your prototxt file with the corresponding proto so you can spot errors right away.

➕ show 1 reply
BurningFrog • 12/08/2024

If you already have a bunch of JSON documents, you can keep using them with JSON5.

That's a big advantage compared to converting to YAML.

➕ show 1 reply