Json and Yaml have similar purpose. We make another detour and look what they have in common and what are the differences.
What sort of data can they be used for?
Basically json and yaml can represent the same sort of data, something we call here a data-tree. In terms of graphs a data-tree is a tree where the inner nodes are labeled either as mappings or as lists and the leave nodes are labeled as bools, numbers, or strings. The edges from the mapping nodes to theirs children are labeled with the key of the respective item whereas the child-edges of a list node have no labels but are ordered.
Sometimes the child-nodes of a mapping are regarded as ordered too. In the json/yaml-string they are ordered by their appearance, but this order is usually not transfered to the deserialized object.
Any data-tree of this sort can be written as json and yaml-string. And any json-string can be seen as the representation of such a data-tree.
What are syntactical differences?
Yaml syntax lets you add string without putting quote signs around unless they are needed for some reason. In json the quote signs are always mandatory. You can use them in yaml too meaning that any string node in json is also a string in yaml. This also applies to other node types, even the mapping and list nodes can be written with in-line format (yaml-speak) where indentation and outer line-breaks becomes irrelevant. That is, any valid json-string is valid for yaml too, and also interpreted the same way.
The following string is valid json and inline-formated yaml. In contrast to block-formated yaml the newlines and indentations irrelevant for the deserialization. Still, they are important for human reading.
"command": "/usr/lib/xorg/Xorg :2 -audit 0 -auth /var/lib/gdm/:0.Xauth -nolisten tcp vt"
What are other differences?
Besides the whitespace-sensitive block-format-syntax yaml has other features unknown to json. Though those yaml-features are not often used.
For instance, in yaml you may use references to previously defined nodes. You can write arbitrary graph-structures in yaml if you like. But more importantly it is used to reflect identity-relation between (sub-)objects that often exist before serialization.
Also, you can add comments, what is convenient because otherwise you would have to provide documentation on the meaning of the keys in a separate document even though often only one instance for the described structure exist. These comments can be added anywhere in the yaml-string likewise comments are added to code and therefor elude a simple modeling in terms the above tree-model.
There are more feature of yaml to tell about but we break off here.
What does this all have to do with bash?
We will see. But we want to mention that today json is the prevalent syntax to serialize data for over-network communication between computational compounds. Whenever you are to use some remote service build in the last say ten years it is very likely that your are expected or at least allowed to communicate with the service using json. People dont talk much about json’s syntax because is such that anyone can understand and use it.
The sort of data it covers, the described data-trees, make a good trade-off between simplicity and expressiveness. More importantly data-trees seem to be somehow a natural model as it fits very well to the object-model of most programming language used today.