The serialization language YAML was developed in 2001, but it wouldn't become very well known until a few more years later. The name was modified from Yet Another Markup Language to YAML Ain't Markup Language a few years later to indicate that developers should use it for data storage rather than document creation (like HTML or Markdown, for example).
We will cover the following:
What is YAML?
YAML is a programming language that is frequently combined with a wide range of other languages and is mostly used for creating configuration files.
When creating configuration files for application projects, languages like Python and the Google-developed Flutter framework for Dart both use YAML (.yaml). Since it can be used to format containerized files, YAML is also well-liked among cloud engineers.
The popularity of the language itself can be attributed to its human-readable features and relatively intuitive syntax. It is regarded as a more readable and helpful format for developers than JSON or XML.
Regrettably, it's not the friendliest for new users, and tiny formatting errors can completely muck up the coding.
For instance, YAML demands a very specific number of spaces spread across numerous lines to depict the hierarchy of data. Since most integrated developer environments don't generate errors for broken YAML code, it can be challenging for a beginner to spot spacing errors, which can occasionally disrupt the development process.
History of YAML
We need to go back to XML, which was the primary configuration language before JSON, to understand why YAML was developed.
Traditional client-server applications employed XML, which is defined by the use of < > blocks, to transmit data. XML was utilized by Java applications, AJAX development, and PHP projects.
Although it was first designed to pass data, XML was eventually expanded to support more logic directly within the document. It was also used to hold configuration settings. Sadly, it was never truly intended for this use.
JSON was introduced to replace XML in this situation, mostly to transmit data to JavaScript in a browser. JSON's largest drawback was likely the lack of a mechanism for comment storage; storing configuration settings was not an acceptable use case for it. JSON syntax is distinguished by its { } blocks and stringent quotation specifications.
YAML emerged as a result of the shortcomings of both XML and JSON. It continued to serve the same function of transmitting data while also addressing some of XML and JSON's shortcomings.
How Does YAML Work?
To make reading and creating code easier, YAML offers tools and patterns that were inspired by those found in other programming languages.
For instance, indentations and new lines may be used to organize code so that, in languages like Python, how it appears on your screen corresponds to how it functions in reality.
As long as you maintain consistency throughout the code you're producing, you can also adjust how deep indentations are to make sure it's as legible for you as possible.
However, you won't be able to use a tab character, which avoids the problem of different operating systems handling tabs differently. Additionally, this disproves the tabs vs. spaces issue.
The two primary data types, lists, and arrays, often known as maps, can be denoted by the [ ] and { } figures in YAML to adopt tighter formatting.
As a result, even though YAML is written for machines rather than people to understand, it effectively becomes a superset of JSON. This language also has characteristics not present in JSON, like comments, for which it wasn't designed.
In Pearl, the data types can be nested to display increasingly complicated structures. Additionally, there are elements borrowed from C, HTML, and MIME as well as mail headers that employ colons to indicate key-value pairs.
Additionally, the space function is present, eliminating the requirement for quote marks around strings and numbers. There is support for ISO-formatted dates and times, and types like integers, clots, and Booleans are automatically detected. However, you can also create your data types.
Multiple documents can be stored in a single file due to structures, and you can use anchors to refer to information in one portion of the document from another (which also lets you duplicate properties or inherent it).
As a result, it is significantly more versatile than JSON, which has a set hierarchy with just one parent node for each child node. Although XML has a comparable option, the YAML parsing expands the references automatically.
By doing this, you obtain a file that is simpler to read and you prevent errors when copying and pasting parameters where just a small number of items differ across multiple instances. However, other systems do not need to be informed of the YAML file's structure.
Features of YAML
These are the features of YAML:
- Data Processing and Representation
An instance document is known as a "Presentation" or "character stream" according to the YAML definition. Scalars, sequences, and mappings are the three main logical building blocks in a YAML instance document. The YAML specification also lists several fundamental restrictions that apply to these fundamental logical constructs. - Delimiter Collision Resistance
YAML is resistant to delimiter collision since its structure is based on indentation. Some languages use padding quote marks, escape sequences, or other workarounds to handle unusual characters. Since YAML is inherently insensitive to brackets and quotation marks, it is simpler to create special characters, especially in strings. - Indented Delimiting
YAML is particularly resistant to delimiter collision since it mostly relies on outline indentation for structure. By simply indenting it in a block literal (using | or >), one can embed XML, JSON, or even YAML documents inside a YAML document because YAML ignores quotation marks and brackets in scalar values. - Non-hierarchical Data Models
YAML also offers a simple relational scheme that enables repeats of identical data to be referenced from two or more points in the tree instead of being entered redundantly at those points, in contrast to JSON, which can only represent data in a hierarchical model with each child node having a single parent. - Practical Considerations
Since YAML is line-oriented, it is frequently easy to transform the unstructured output of current programs into YAML format while preserving the majority of the original document's appearance. Generally, it is simple to generate well-formed YAML directly from distributed print statements within simple programs because there are no closing tags, braces, or quotation marks to balance. - Security
Since YAML is just used to represent data, it lacks any executable commands. Although secure parsing and validation are essential in all data languages, their implementation is such a notorious security vulnerability that YAML's lack of a companion command language may be a relative security gain.
Where can YAML be Used?
YAML isn't a development language, despite what some people claim. Keep in mind that none of the three data structure formats (XML, JSON, and YAML) were created to include any logic in the file structure itself. A programming language ought to be able to handle this.
For storing configuration settings across many programming languages and DevOps platforms, YAML has emerged as the standard.
Ansible, a configuration management system, was one of the first significant YAML adopters. System administrators and DevOps teams can use Ansible to create files defining a machine's or piece of software's configuration or to install software packages that will be used by a deployment script (called a playbook). What were once manual procedures can now be automated due to the YAML framework.
More recently, YAML has been widely utilized for several things, including:
- Docker (Dockerfile)
- Kubernetes
- Puppet
- AWS CloudFormation
- Azure DevOps Pipelines
- GitHub Actions
- Relay
The relevant YAML (.yml) file for each of these tools includes the configuration options and settings for a particular deployment.
The structure of an application service, the container image to use, the number of replicas to deploy, whether or not the service should be behind a load balancer, the authorization that connects the container registry, and other details are all defined in a Kubernetes YAML file.
As yet another example, Azure DevOps is moving away from the old editor, which served as the primary tool for developing DevOps pipeline tasks in Visual Studio Team Services (VSTS) and Team Foundation Server (TFS), and toward the YAML format.
Another DevOps pipeline engine that completely relies on YAML is GitHub Actions. Pipelines as code, a new concept, was produced by using YAML as the configuration file structure.
The use of a yml-text-based file generates effective pipeline deployment processes that store task information together with pertinent configuration data.
One of the biggest advantages is that your pipeline can now be included in the source control or version control component, such as Git, which generally just manages application source code.
Conclusion
As we've seen, YAML is a popular language for data serialization. It's simple to read and simple to learn. Since YAML is already widely used, it won't be long before you need to write or modify YAML on your own whether you work in development or DevOps.
Further Reading:
Digital Experience Monitoring (DEM)
Monitor Your Entire Application with Atatus
Atatus is a Full Stack Observability Platform that lets you review problems as if they happened in your application. Instead of guessing why errors happen or asking users for screenshots and log dumps, Atatus lets you replay the session to quickly understand what went wrong.
We offer Application Performance Monitoring, Real User Monitoring, Server Monitoring, Logs Monitoring, Synthetic Monitoring, Uptime Monitoring, and API Analytics. It works perfectly with any application, regardless of framework, and has plugins.
Atatus can be beneficial to your business, which provides a comprehensive view of your application, including how it works, where performance bottlenecks exist, which users are most impacted, and which errors break your code for your frontend, backend, and infrastructure.
If you are not yet an Atatus customer, you can sign up for a 14-day free trial.