What is the difference between YAML and JSON?
YAML is a superset of JSON. From the YAML official specs: "YAML can therefore be viewed as a natural superset of JSON and every JSON file is also a valid YAML file. YAML offering improved human readability and a more complete information model. This makes the migration between JSON and YAML very easy if the additional features are required.". YAML has more features than JSON, like inline comments and relational anchors. YAML also support more complex data types and embedded block literals than JSON. It is possible to write recursive structures and duplicate keys in yaml. From performance perspective, due to the simplicity, JSON processing performance is better than YAML and It is probably still interoperable with more systems.
When to use JSON? When to use YAML?
Since JSON is good for the performance and interoperable, it is better to use JSON for system-to-system communication, for example, most of HTTP Restful requests use JSON to communicate between the server and client. And since YAML is the winner of readable and maintainable, it is better to use YAML in human maintained files, for example, configuration files.