In Defense of YAML

41 points by nrposner


hailey

It's odd to describe YAML as arising to fill a gap in JSON. I have a recollection of YAML coming out of the perl community, which I thought suggests that it might be as old or even older than JSON.

So I went digging to find the actual history, and found quite an interesting post from Ingy dot Net, one of the creators of YAML, which puts its genesis somewhere between November 1999 and January 2001.

I also found another post on the history JSON, which puts a primordial form of JSON (using a hidden iframe to send a message embedded in a <script> tag from the server to client) at April 2001, though the technique might be older than that. JSON did not become a format in its own right until 2002 when Douglas Crockford published json.org.

So YAML seems to slightly predate JSON, though more charitably it would be fair to suggest that they developed concurrently. It's not accurate to describe it as a reaction to JSON or arising to fill a gap in JSON. Instead, YAML was actually a reaction to XML. JSON's reason for becoming was more practical - literally embedding data in <script> tags - though it too was well placed as a simpler alternative to XML when the pendulum started swinging back, and it is undeniable that this played a large role in its popularity.

Anyway, the article has hints of LLM writing imo. I see that the project it's announcing is vibecoded too.

rbuchberger

With inline tables The "bad" TOML example becomes:

[services.web]
image = "nginx:latest"

environment = { 
  DB_HOST = "postgres",
  DB_PORT = 5432,
}

resources.limits = {
  memory = "512M",
  cpu = "0.5",
}

Seems fine to me, fewer characters than the YAML example if we're golfing about it.

lhearachel

I believe that this is out of scope for the stated aims (to defend YAML), but I wish that this post discussed TOML 1.1 and its new inline tables feature. I find that it addresses my three main gripes with JSON:

  1. It supports unquoted key-names,
  2. It has comment-strings, and
  3. It allows trailing commas.
chrismorgan

I dislike YAML because of things like the Norway problem (which is still a problem for strings like "", "Null", "true" and "FALSE" because of unquoted strings—you need a YAML-aware encoder) and its general complexity, even though YAML 1.2 dialled it back a little (a little); but you know the reason why I despise YAML?

tab characters must not be used in indentation

When indentation is load-bearing, it’s fine to disallow mixed or inconsistent tabs and spaces; Python 3’s approach seems pretty good:

Indentation is rejected as inconsistent if a source file mixes tabs and spaces in a way that makes the meaning dependent on the worth of a tab in spaces; a TabError is raised in that case.

But YAML is the only file type that I can think of which, permitting indentation (optional or mandatory), doesn’t support both tabs and spaces.

(Oh, you say Make doesn’t support spaces? You can set .RECIPEPREFIX to something other than tab. I could even argue that the tab isn’t indentation, as Make uses it.)