YAML – Yet Another Markup Language

In computer programming, YAML stands for YAML Ain’t Markup Language (it was originally intended to mean “Yet Another Markup Language”). It is a human-readable data serialization language. This means it’s designed to represent data in a format that is easy for humans to read and write, while also being easily parsed by computers.

Here’s a breakdown of what that means in the context of computer programming:

Data Serialization Language: YAML is used to take data structures (like lists, dictionaries, and scalar values such as strings and numbers) and convert them into a text-based format that can be easily stored in files or transmitted across networks. This process is called serialization. The reverse process, converting the text back into data structures, is called deserialization or parsing.

Human-Readable: This is a key feature of YAML. It uses a simple syntax that relies on indentation (like Python) to define structure, rather than relying heavily on symbols like braces {} and brackets [] as in JSON, or tags like <tag> as in XML. This makes YAML files much easier for developers and system administrators to understand and modify directly.

Configuration Files: YAML is very commonly used for writing configuration files for software applications, systems, and services. Its readability makes it ideal for defining settings that humans might need to review or edit. Examples include configuration for:

  • Automation tools like Ansible.
  • Container orchestration platforms like Kubernetes and Docker Compose.
  • Continuous integration/continuous deployment (CI/CD) pipelines.

Data Exchange: While JSON is more prevalent for data exchange over the web (especially with APIs), YAML can also be used for this purpose, particularly in systems where human readability and the ability to include comments are valued.

Superset of JSON: YAML 1.2 is a superset of JSON, meaning that every valid JSON file is also a valid YAML file. This allows for some interoperability between the two formats.

Key features of YAML include:

  • Indentation: Uses whitespace indentation to define structure and nesting. Tabs are generally not allowed; spaces are used consistently.
  • Key-value pairs (Mappings): Represented using a colon and a space (e.g., name: John Doe).
  • Lists (Sequences): Represented using a hyphen and a space (e.g., – item1).
  • Scalars: Basic data types like strings (can be quoted or unquoted), numbers (integers, floats), booleans (true, false), and null values (null).
  • Comments: Lines starting with a # are treated as comments and ignored by the parser.
  • Multi-line strings: Supported with literal (|) and folded (>) block styles.
  • Anchors and Aliases: Allow referencing and reusing parts of the document, reducing redundancy.
  • Multiple Documents: A single YAML file can contain multiple separate documents, separated by —.

In summary, YAML is a programmer-friendly data serialization format that prioritizes readability and is widely used for configuration files and data representation in various software development and infrastructure automation contexts.