Search code examples
yamlsimplifysimplification

Have any simplified YAML formats become widespread?


I love YAML.

Wait, let me back up. I love YAML that looks like this, even more than JSON:

Projects:
  C/C++ Libraries:
  - libyaml       # "C" Fast YAML 1.1
  - Syck          # (dated) "C" YAML 1.0
  - yaml-cpp      # C++ YAML 1.2 implementation
  Ruby:
  - psych         # libyaml wrapper (in Ruby core for 1.9.2)
  - RbYaml        # YAML 1.1 (PyYaml Port)
  - yaml4r        # YAML 1.0, standard library syck binding
  ...

I love YAML anchors and references too, and sometimes wish JSON had them.

But I hope most of us can agree that the following is not so human readable (I know this example is didactic, but the point is since it is valid YAML, people you're collaborating with could pollute your data with such features):

!!map {
  ? !!str "sequence"
  : !!seq [ !!str "one", !!str "two" ],
  ? !!str "mapping"
  : !!map {
    ? !!str "sky" : !!str "blue",
    ? !!str "sea" : !!str "green",
  },
}

So I'm disappointed I can't find any widespread coups to standardize a simplified subset of YAML, at least with a cursory Google search.

Does anyone know of one?


Solution

  • There are many such subsets. Almost every YAML library defines one implicitly by the format that results from round-tripping (loading YAML into internal data and serialising the data back to YAML).

    You often can influence these subsets, but they tend to have useful defaults with block structure for larger collections and flow-style for smaller ones (each according to what the library developer considered readable).

    IMO the way to deal with rogue editors is to round-trip the code through the yaml utility (of which I am the author) that comes with ruamel.yaml parser, and then use it. If you don't like the subset it forces on you, it is should be relatively easy to make changes to its serializer settings by experimenting. Such "normalisation" is IMO a must before storing/updating any YAML file in a revision control system.