Definition

What is YAML (YAML Ain't Markup Language)?

YAML (YAML Ain't Markup Language) is a data serialization language used as the input format for diverse software applications.

An application user or administrator specifies data in a YAML file that the application then reads. For example, YAML files can define users or install software packages on servers.

When YAML debuted in May 2001, the acronym stood for Yet Another Markup Language. By the start of 2002, the language's creators had changed the acronym's meaning to the recursive YAML Ain't Markup Language. While YAML's structure resembles a markup language, it is not used for document markup.

Applications that use YAML include the configuration management tool Ansible, the container orchestrator Kubernetes and the orchestration engine OpenStack Heat. The programming language Python relies on the YAML syntax, and most programming languages can interpret it.

How is YAML used?

YAML is a highly flexible programming language that can be used for the following.

Configuration management

With YAML, programmers can define files, settings and parameters for applications and services. Docker uses YAML to define multicontainer application services, networks and volumes. Ansible uses YAML to define the automated provisioning of resources and rules for how software is to be installed. Kubernetes uses YAML to automate resource deployment and management.

Data exchange

YAML facilitates data exchange between different programming languages because it can be easily generated and parsed by many different languages. It can also be used to define application programming interfaces, API endpoints, and request and response codes. These capabilities assist in system integration.

Document generation

The structure and content of documents can be defined in YAML, which then takes this information and applies it to multiple APIs that are navigated in automated documentation workflows.

Advanced integration

YAML is used to define integration pipelines and workflows in systems -- from build and test through deployment. GitLab and CircleCI are two development platforms that use YAML to define their continuous integration/continuous delivery pipelines.

On-premises and cloud infrastructure

YAML can define data center infrastructure operations, such as the automated provisioning and management of IT resources. It can also be used to manage infrastructure components and operations in the cloud. For example, AWS CloudFormation provides YAML templates that can be modified to define cloud infrastructure.

Content management

Front-end content provided by YAML can be used to define metadata, such as titles, dates, tags and authors, for webpages and posts. This simplifies content management for website developers and managers.

Key-value pairs in YAML

YAML uses value pairs to define the keys and values of data. As an example, these keys can be customer name and age keys, such as Elliot and 35, or they could be listed as the items needed for a computer system configuration.

Key-value pairs in a YAML program are defined and separated with a colon and at least one space. The keys are unique identifiers to which one or multiple values can be assigned. YAML keeps data stored as a map containing the keys and the values associated with those keys. The value associated with each key can be of any data type.

The following is an example of how key-value pairs are used in YAML.

State: Nevada
Capital: Carson City

In this example, State and Capital are keys, and Nevada and Carson City are their corresponding values.

If a YAML programmer wants to create a more complex data structure, they can nest keys in the following multilevel data structure so that data meets all key parameters before it is selected.

State: Nevada
Capital: Carson City
location:
  - North Carson Street

In this example, the program is looking for data specific to North Carson Street, where the Nevada State Capitol building is located, in Carson City, Nev. All data selected must meet these parameters.

What does a YAML file look like?

The following are examples of basic YAML syntax in action.

The following demonstrates how to enter values into a list and use a # sign as a comment to explain what the list contains.

#List of customers
Customers>
 <Customer>
 <name> Haynes Company </name>
 <department> Purchasing </department>
 <country> USA </country>
 </Customer>

The following shows how to ask YAML to parse values and include a comment for documentation.

# parse this value as a string
date: !!str 2025-04-15

The following shows how to create a string in YAML, surrounding it with quotes.

"June 21 is the first official day of summer!"

The following defines a data source.

### dictionary
 mysqldatabase:
 hostname: localhost
 port: 2501
 username: root
 password: root

YAML vs. JSON

YAML is frequently an alternative to the data interchange format JavaScript Object Notation (JSON). Both are alternatives to Extensible Markup Language (XML). Although YAML and JSON are intended to be human-readable formats, JSON more easily transfers from one programming language environment to another.

Best practices for using YAML

Like other programming languages, there are best practices for coding YAML in the most efficient and usable way, including the following:

  • Apply consistent indentation. Unlike most other programming languages, YAML does not use tabs for indentation. Instead, spaces are used for indentation and code nesting. The recommended practice is not to exceed eight spaces for any indentation, with the preferred number of spaces being two.
  • Use quote marks. YAML uses the term scalars for programming strings or arrays. Although scalars do not necessarily require quote marks to surround them, it is a recommended practice to use quote marks.
  • Employ backslashes. If quote marks are used with YAML strings, each line break must be prefaced with a backslash.
  • Add comments. Comments (#) aid in the usability and readability of YAML files.
  • Verify using linter tools. YAML comes with linter tools that can check the accuracy of YAML syntax. Programmers should use these tools to check for coding syntax errors as part of the YAML debugging process.
  • Use integrated development environments (IDEs). Many commercial and open source providers offer IDE plugins, including Eclipse, IntelliJ, Microsoft and Red Hat, that also point out YAML syntax errors.

Avoiding pitfalls when writing YAML

The following are some critical pitfalls to avoid when writing YAML code:

  • Check indentation. Because YAML uses spaces instead of tabs for indentations, it is easy to mix tabs with spaces, which can create parsing errors.
  • Use quote marks liberally when YAML scalers are being defined. Although YAML scalers do not technically require quote marks like other programming language arrays and strings do, use quote marks anyway.
  • Always declare Boolean true and false values. In some cases, values that are not intended to be true or false can be misinterpreted. To avoid this, use the !!bool command to interpret the value as true or false.
  • Use quote marks when using special characters. YAML uses many special characters in its programming commands, so it is best to surround special characters that are parts of strings in quote marks to avoid misinterpretations.
  • Do not nest too deeply. Limit nesting to a maximum of four levels to avoid overcomplication.
  • Validate YAML files for syntax accuracy prior to deployment. Erroneous YAML syntax can generate production failures.

Learn how data serialization languages, like XML and YAML, compare when used to transfer data between applications.

Continue Reading About What is YAML (YAML Ain't Markup Language)?

Dig Deeper on Systems automation and orchestration