It sounds funny to know, but YAML stands for "YAML Ain't Markup Language." Well, contrary to its unserious nomenclature, it’s considered a pretty widely used data serialization format known for good human readability and scalability.
The theory becomes funnier when we realize that YML is simply a brief alternative to YAML, which has been done for some practical purposes. Yet, there are some interesting differences in the story of their evolution, including each of their use cases, in this blog.
What is YAML?
YAML is a format for structuring and storing data that is easy for both humans and machines to understand. It allows humans to write and edit the data easily, while computers can read and process it efficiently. Therefore, YAML is defined as a human-readable data serialization format.
Data serialization essentially means converting data structures (arrays/objects) to linear format (string/binary data) and storing them in a file or exchanging them between systems—all without changing their structure. Consider this similar to packing a parcel box, ensuring its items stay intact while shipping.
Evolution story of YAML
It was initially in 2001 when three developers named Clark Evans, along with Ingy döt Net and Oren Ben-Kiki, designed the YAML format. At the initial, it represented “Yet Another Markup Language,” but for some reason, it was later changed to “YAML Ain’t Markup Language.”.
Why was YAML even created?
Although existing formats like XML and JSON have been widely accepted and used for data serialization, they fail to be flexible, brief, and human-readable. There is a gap and an absence of an intuitive, extensible, lightweight, and concise format option. YAML was designed to cater to all such use cases and serve developers worldwide in a ‘better-to-work-with’ format.
As part of the YAML configuration, any files under this format were assigned the file extension .yaml
officially.
How did YML come into the picture?
After the YAML format was designed and finally introduced, it secured massive adoption by developers worldwide throughout the early 2000s. However, with this, a couple of technical limitations and difficulties were also faced:
1) Three-Character Limit for Extensions:
The prevailing legacy operating systems at the time included early versions of Windows and primarily MS-DOS (Microsoft Disk Operating System). These systems essentially only allowed a length of up to three characters. As a result, there was an unsaid convention by the developers to start shortening the extension to .yml
instead of using the official .yaml
extension.
Surprisingly, YML could successfully fit within the system’s constraints and environments. That’s how YML came into the picture, implicitly!
2) Developers’ Convenience:
Later, after the systems were upgraded and evolved to accommodate high character limits to extensions, the developers still somehow chose .yml
the shorter version due to reasons like ease of typing and command-line workflows.
However, even though the official .yaml
extension format could have been used, developers made it .yml
more acceptable to use.
YAML vs. YML - What’s the Correct Syntax?
YAML parsers refer to the libraries or tools that read and process files formatted in the YAML language. When any file with .yaml
an .yml
the extension will be executed, the YAML parser wouldn’t differentiate but rather treat them as the same.
Therefore, in the case of file extensions, both mean the same. The data stored inside the file will be read and processed in the same way.
Why Both .yml
and .yaml
Still Exist Today?
It often creates a big confusion about the existence of .yml
and .yaml
together, while both are pretty widely used. Here’s how we differentiate the two:
YAML: It is a data-serialization format/standard in itself similar to XML, JSON, etc. It is a language that is used for data serialization. YAML is a format, a language, and a file extension altogether.
YML: Just a file extension used and seen as
.yml
for the YAML-formatted data files.
The continued existence of .yml
alongside .yaml
is due to a mix of legacy reasons, developer habits, and tooling flexibility.
Any file named with .yaml
or .yml
file extension typically represents that the data inside is in the YAML format.
What do we use YAML for ?
There are a couple of benefits of the YAML format over others. Some of the benefits include:
human-friendly structure, easy to visualize
clean syntax
simplicity for brackets or tags
efficient for machines,
lightweight and flexible format
allows customizable data structures based on configuration needs
Thus, YAML is set to be an ideal format for data serialization. Let’s see where we can use YAML as a real-world use case:
Real-World Use Cases of YAML
-
Configuration Files:
- Similar to the role a blueprint plays in a building construction, YAML defines how any service or application must be configured. For instance, it
docker compose
uses YAML in order to define the networks, services, and volume of any Docker application out there.
- Similar to the role a blueprint plays in a building construction, YAML defines how any service or application must be configured. For instance, it
-
Data Serialization:
- YAML helps serialize data (converting complex data structures into a format that can be saved or transmitted). This could again be related to the blueprint and construction analogy. Just like a blueprint provides a model about how everything gets assembled, YAML helps serialize data so that data transfer becomes seamless and easy across different software components (like microservices, web servers, CI/CD pipelines, etc.).
-
Infrastructure as Code:
- Just the way any building’s blueprint tells about its planned infrastructure and its organization, YAML could be used in cloud services like infrastructure as code tools (for instance: Kubernetes, Ansible). By this, YAML is responsible for delivering the necessary information related to the infrastructure, config, and deployment pipelines for any opted cloud servers/services.
-
Example of YAML (Blueprint for an App Configuration):
app: name: MyApp version: 1.0 settings: debug: true max_connections: 100 environment: production database: host: db.example.com port: 5432 user: admin password: secret
Just the way any build Therefore, any YAML file significantly helps in breaking down any application’s configurations into logical components like app name, database information, settings, etc.
YAML in Modern Tools
YAML has become a cornerstone in modern software development. Some key areas where YAML plays a vital role include:
- Kubernetes: YAML files define pods, deployments, and services in Kubernetes clusters. For example, a deployment manifest in YAML might look like:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: app-container
image: my-app-image:v1
- Keploy: YAML plays an integral role in automating testing workflows. Autogenerated test cases and mocks are stored in YAML format within the test suite, making them both human-readable and easily editable.
version: api.keploy.io/v1beta1
kind: Http
name: test-1
spec:
metadata: {}
req:
method: POST
proto_major: 1
proto_minor: 1
url: http://localhost:8010/product
header:
Accept: '*/*'
Content-Length: "43"
Content-Type: application/json
Host: localhost:8010
User-Agent: curl/7.88.1
body: "{\n \"name\":\"Bubbles\", \n \"price\": 123\n}"
timestamp: 2024-06-05T16:53:56.839574946+05:30
resp:
status_code: 201
header:
Content-Length: "37"
Content-Type: application/json
Date: Wed, 05 Jun 2024 11:23:56 GMT
body: '{"id":2,"name":"Bubbles","price":123}'
status_message: Created
proto_major: 0
proto_minor: 0
timestamp: 2024-06-05T16:53:58.94794204+05:30
objects: []
assertions:
noise:
header.Date: []
created: 1717586638
curl: "curl --request POST \\\n --url http://localhost:8010/product \\\n --header 'Accept: */*' \\\n --header 'Content-Type: application/json' \\\n --header 'Host: localhost:8010' \\\n --header 'User-Agent: curl/7.88.1' \\\n --data '{\n \"name\":\"Bubbles\", \n \"price\": 123\n}'"
Conclusion
YAML is widely accepted to be an indispensable data serialization format due to its simplicity, flexibility, and readability. Thus, it’s ideal for any of the modern software development needs. The humorous origin of its name and the confusing coexistence of .yaml
and .yml
file formats were the primary focus of this blog. We’ve seen how YAML proves to be a really versatile tool for bridging the gap between human-friendly data representation and machine efficiency.
FAQ’s
Can we convert .yml
to.yaml
?
Yes, you can convert the former .yaml
and vice versa by simply renaming the file.
Why are some tools still used .yml
by default?
Though there’s no difference in functionality, some tools are still used. YAML tool by default due to its frequent usage out of developer preferences, historical reasons, and legacy support.
What are some of the use cases of YAML?
It is used in CI/CD pipelines (like GitHub Actions and GitLab CI), DevOps, cloud services (like Infrastructure as Code), and configuration management (for instance, Kubernetes, Docker, etc.).
Top comments (0)