Is JSON really a subset of YAML?
YAML is a superset of JSON.
This is a basic truth about YAML.
I assume that in 2025, most people who use YAML and JSON regularly already know this.
Today I'll say a bit more about this and how it came to be.
2001, 2006 and 2009🔗
The fact that JSON is a subset of YAML is more of a happy accident than something that was planned.
I started working on YAML with Clark and Oren in April 2001.
We didn't become aware of JSON until 2006. That seemed to be the same time that almost everyone was becoming aware of JSON.
I was surprised to learn much later that JSON also started in 2001!
By 2006, the YAML 1.1 spec had already been published.
When we took a closer look at JSON, we realized that it was basically YAML's flow style collections with double quoted strings.
When we looked really closely at JSON, we realized that there were only 3 small issues that prevented JSON from being a subset of YAML.
One of them was that the colon separator for key/value mapping pairs must have a space after it. JSON has no such requirement.
We decided to take advantage of this situation and make JSON a proper subset of YAML for the 1.2 spec.
For the colon thing we made the special rule that in a flow mapping, if the key is double quoted (which all JSON keys are), then the colon doesn't need whitespace after it.
I forget the other two issues. It was a while ago!
That came out in 2009.
But is JSON really 100% a subset of YAML?🔗
As far as we (the current core YAML dev team) know, yes, JSON is really 100% a subset of YAML.
This has been challenged from time to time.
Each time that it is challenged, we have to go back and look at the spec closely and check. So far we have fallen on the happy YAML side.
It's entirely possible that there is a corner case that we have missed.
IF someone finds one, I guess we'll have to put out a new YAML 1.3 spec.
The importance of JSON, YAML and YS🔗
JSON is a very simple and trustworthy format.
It's hard to mess it up.
It's super reliable for data that you don't have to look at or maintain.
YAML is better for that.
Since JSON is a subset of YAML, you can easily write and maintain data in YAML and then convert it to JSON for the machine.
JSON plays an important role for YS too.
YS considers JSON to be the Lingua Franca of data.
When you load a file with YS, the return value is always a data structure of the JSON data model.
In fact, a libys.so binding library for any given programming language currently has one function:
The load
function takes a YS/YAML/JSON string and returns a JSON string that
is then decoded by the library into a native data structure for that language.