BudiBadu Logo
Samplebadu
YAML

Learn YAML by Examples

1.2

YAML (YAML Ain't Markup Language) is a human-readable data serialization format designed for configuration files and data exchange between programming languages. It emphasizes readability with a clean syntax that uses indentation and minimal punctuation, making it easier to read and write than JSON or XML while remaining machine-parseable.

These examples cover essential YAML features from basic syntax to advanced concepts, helping you write clear and maintainable configuration files.

Key–Value Pairs

This code example demonstrates the fundamental building block of YAML: key–value pairs. Learn how to define clear data mappings, handle special characters in keys, and structure nested data for configuration files.

Indentation Rules

This code example illustrates the strict indentation rules in YAML. Understanding proper spacing and structure is fundamental to writing valid YAML files.

Block vs Flow Styles

Explore this sample code to understand the difference between Block and Flow styles. Learn when to use the readable, indented block format versus the compact, JSON-like flow format.

Quoted vs Unquoted Strings

This code example clarifies when to use quotes for string values in YAML. Learn about unquoted scalars, single quotes for literals, and double quotes for escape sequences.

Boolean Values

Learn how to represent boolean values correctly with this sample code. Understand the differences between standard booleans and legacy values.

Null Values

This code example demonstrates the multiple ways to represent null values in YAML, including explicit keywords, symbols, and empty values.

Numeric Types

Explore this sample code to understand how YAML handles numeric types, including integers, floats, scientific notation, and different number bases.

Date & Timestamp Values

This code example covers formatting dates and timestamps in YAML, leveraging ISO 8601 support for robust time handling.

Sequences

Learn how to define lists and arrays using this YAML sequence sample code. Understand the versatility of block and flow styles for collections.

Mappings

This sample code explains how to structure objects using YAML mappings. Master key-value pairs, nested dictionaries, and different syntax styles.

Anchors

This code example demonstrates how to use Anchors (&) to define reusable data chunks. Learn to keep your configuration DRY (Don't Repeat Yourself) by marking nodes for reference.

Aliases

Learn how to use Aliases (*) and Merge Keys (<<) to reference and inherit anchored data in this sample code. Master the art of overriding default configurations.

Multi Line Strings

This sample code explores the powerful text handling features of YAML, specifically how to manage multi-line strings, preserve formatting, or fold text.

Nested Structures

Explore deep nesting of lists and maps with this complex sample code. Understand how indentation defines hierarchy in complicated real-world data.

Tags

This code example shows how to use explicit Tags to enforce data types, handle binary data, and use custom application schema.

Comments

Learn best practices for documenting YAML files using comments in this sample code. Understand syntax, placement, and limitations.

Directives

This code example illustrates YAML directives and multi-document support. Learn how to specify versions and manage multiple logical files in one stream.