YAML: Yet Another Markup Language

niccolo

Joel Amos

Posted on September 13, 2024

YAML: Yet Another Markup Language

Is it a failed language?

Introduction
YAML(YAML Ain’t Markup Language) is a human-friendly data serialization language for all programming languages. Originally developed by Clark Evans, Ingy döt Net, and Oren Ben-Kiki in 2001, it is a human-readable data serialization language, commonly used for configuration files. Same as Extensible Markup Language(XML), YAML targets communication applications, but slightly differs from Standard Generalized Markup Language(SGML) with its minimal syntax.

Although custom data types are allowed, YAML at its core encodes scalars (strings, integers, and floats), lists and associative arrays(maps, dictionaries or hashes) based on the Perl programming language. YAML uses a colon-centered syntax for expressing key-value pairs. It uses an indentation style similar to Python’s, escape sequences similar to C’s, and whitespaces wrapping inspired by HTML.

History

YAML got its name after being released in the wrong era which witnessed a lot of proliferation of markup languages for presentation and connectivity. The markup languages released in that era include HTML, XML, SGML, etc. Its name was a recursive acronym to dispute its functionality and purpose as a data-oriented language rather than a markup language as was claimed.

Over the years since its inception, YAML has released various versions with additional features and updates based on the first beta( YAML 1.0 ) which was released on the 29th of January, 2004 with its primary goal as a means to create a format that was more readable and writable by humans compared to existing data formats like XML and JSON.

Versions
Subsequent versions were released later on and they include:

  • YAML 1.1 - 18 January 2005 : This version introduced enhancements and clarifications to the original specification, focusing on improving the handling of data types and various data structures .

  • YAML 1.2.0 - 21 July 2009 : Closely aligning to JSON, this release simplified the format and aimed to eliminate some obscurity present in the earlier releases.

  • YAML 1.2.1 - 1 October 2009 : This release was aimed at making YAML a superset of JSON, ensuring any valid JSON document is a valid YAML document.

  • YAML 1.2.2 - 1 October 2021 : The main of this release was continual refinement of YAML, with the core principles still the same. The main focus of the update was to improve usability and expand the format’s capabilities while maintaining its readability.

Syntax

YAML has a simple syntax designed with readability in mind. The indentations in its syntax denote structures.
Its key features include:

  • Human-Readability: The use of indentation to represent nested structures, visually declutters the script.

  • Data Types:
    Scalars: Represent simple values such as strings, numbers, and boolean.
    Sequences: Represent ordered lists (arrays). Commonly denoted by a dash ( - ) followed by a space.
    Mappings: Represent key-value pairs (dictionaries). They are denoted by a colon (:) followed by a space.

  • Complex structures:
    Nested Sequences and Mappings: YAML supports nested structures, allowing complex data to be represented hierarchically.
    References: It allows the use of anchors (&) and aliases (*) to reuse and reference data within the same document.

  • Formatting Rules:
    Indentation: It relies on indentation ( 2 to 4 spaces ) for nesting. NB: Tabs are not allowed.
    Line Breaks: For multiple-lined strings, YAML provides various options like folded style ( < ) and literal style ( | ).

  • Comments: Comments are denoted by a #. They can be placed on their own or at the end of a line.

  • File Extensions: They typically use .yaml or .yml extensions.

  • Interoperability: Supports JSON documents as it is a superset of JSON. Integration of JSON with YAML is easier.

An example of a YAML syntax:

--- # Favorite movies
- Casablanca
- North by Northwest
- The Man Who Wasn't There

--- # Shopping list
[milk, pumpkin pie, eggs, juice]

--- # Indented Block
name: John Smith
age: 33

--- # Inline Block
{name: John Smith, age: 33}

--- # Strings
data: >
   Wrapped text
   will be folded
   into a single
   paragraph

   Blank lines denote
   paragraph breaks

---
example: >
        HTML goes into YAML without modification
message: |
        <blockquote style="font: italic 1em serif">
        <p>"Three is always greater than two,
           even for large values of two"</p>
        <p>--Author Unknown</p>
        </blockquote>
date: 2007-06-01

Enter fullscreen mode Exit fullscreen mode

Conclusions

Bearing in mind that YAML is still used widely in build and testing production-level environments, it proves to be an essential tool for managing configurations and data interchange. Its readability and flexibility make it a popular choice for defining automation scripts in Ansible , where it streamlines IT task automation. Similarly, YAML's role in GitHub workflows facilitates the configuration of CI/CD pipelines, making testing and deployments more efficient. The continued evolution and integration of YAML in these critical areas underscore its ongoing relevance and effectiveness in simplifying complex workflows and configurations.

Follow me on Github for more on programming languages.

💖 💪 🙅 🚩
niccolo
Joel Amos

Posted on September 13, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related