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.
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.
yq some.yaml -o jsonThat one is likely more relevant than yq since folks in the json ecosystem are far more likely to be familiar with jq's syntax and thus using gojq is "one stop shopping," not to mention that its error handling is light-years beyond jqlang's copy
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/If YAML is a strict superset, wouldn't that mean that YAML must have at least one feature that is not part of JSON? Wouldn't that make it impossible to define all YAML files as valid JSON?
For a feature like references, you'd have to do the annoying thing and duplicate that section of the file.
For a feature like unquoted strings or extra commas, you just quote the strings or remove the commas.
The various YAML features are in between and mostly close to the latter.
Yes. One of the features YAML supports is the widely documented format we are all familiar with.
However, being a "strict superset of JSON" also means a conformant YAML implementation can load a "pure" JSON resource without issue. The converse is not generally possible as JSON cannot express what YAML can, such as octothorpe ('#') comments.
HTH
EDIT: see also https://news.ycombinator.com/context?id=42361994
Where arrays and objects just look too similar (IMO), white space is significant, most strings are unquoted, etc. And personally I find it quite difficult to really understand what’s going on there, at a glance, compared to JSON (or JSON5).
So what? YAML can be trivially mechanically translated between flow and block syntax.
Additionally plugins let you link your prototxt file with the corresponding proto so you can spot errors right away.
That's a big advantage compared to converting to YAML.