Why use YAML over JSON for configuration files?

Why use YAML over JSON for configuration files?

Nowadays one of the main purposes of using file types like XML, YAML and JSON is for configuration. They obviously still retain plenty other uses such as transporting data over the internet.

Having configuration values in your system is highly recommended so that you don't have to hardcode settings that can change depending on third party libraries or settings. Moreover, you can also have different configurations for different environment: development, acceptance or production.

For me, the best pull request is one in which codes are not added, but in fact, reduced; using configs is one of the way to achieve that. You also decouple your application logic from things that regularly change.

Why use YAML?

When I started learning programming during my University years, XML was the defactor industry standard for both data and configuration. It became even more popular with the boom of Android Mobile development, which used a lot of XML.

I personally find XML too verbose with lots of noise - especially true with deep nested tags. Fortunately there is plenty of software viewers to get or extract the data in a much cleaner way.

By the end of my course, JSON started becoming popular especially in the world of Web Development with composer.json in php and package.json for NodeJS.

For me, with years of working mostly with JSON, it is my default configuration file type. But recently, in my previous job at this time of writing, I worked a lot with docker, especially the docker YAML file. Before that, I use it with Jekyll as a static site generator and a lot of Ruby on Rails in my side projects with files like database.yml.

You can also use YAML as configuration in Azure DevOps, which I've touched upon for a couple of months in order to automatically launch Web Automation after a release pipeline is built.

In this automation project, I use a config.json file to hold configuration values such as credentials and access keys.

This time for a mobile automation project, I decide to do some research before using JSON directly. I am pointed to several options from StackOverflow and in the article below, the author describes how there are better alternatives to JSON as a configuration language.

However, JSON is actually a pretty terrible configuration language for a number of reasons. Don’t get me wrong — I like JSON. It is a flexible format that is relatively easy for both machines and humans to read, and it’s a pretty good data interchange and storage format. But as a configuration language, it falls short.
Why JSON isn’t a Good Configuration Language

The point that resonates best with me the most is that YAML is much cleaner and simpler to read.