Skip to main content
Version: 1.3.0

YAML in 2 minutes

YAML (a recursive acronym for "YAML Ain't Markup Language") is a human-readable data serialization language. It is commonly used for configuration files and in applications where data is being stored or transmitted. YAML aims to be easily readable by humans and straightforward for software to parse.

Stream2Vault uses YAML extensively for defining your Data Vault model objects (Hubs, Links, Satellites, etc.) and their sources.

Basic Structure

YAML's structure is based on indentation to denote structure and relies on a few core concepts:

  1. Key-Value Pairs (Mappings): The most fundamental structure in YAML is the key-value pair, also known as a mapping or dictionary.
    key: "value"
    name: John Doe
    age: 30
    isStudent: false
tip

Usage of single ' or double " quotes for string variables is optional. The following mappings are equivalent:

name: Jane Doe
name: 'Jane Doe'
name: "Jane Doe"
  1. Lists (Sequences): Lists (or arrays/sequences) are denoted by a hyphen (-) followed by a space. Each item in the list is on a new line with the same indentation.

    fruits:
    - Apple
    - Banana
    - Orange

    # Or an inline list (less common for complex items)
    colors: [Red, Green, Blue]
  2. Nested Structures: YAML allows for complex data structures by nesting mappings and sequences. Indentation is crucial here.

    person:
    name: Jane Doe
    age: 28
    address:
    street: Mariendorfer Damm
    city: Berlin
    hobbies:
    - cooking
    - coding
  3. Scalars (Data Types): YAML automatically detects common data types:

    • Strings: hello world, 'quoted string', "double-quoted string"
    • Numbers: 123 (integer), 3.14 (float)
    • Booleans: true, false, yes, no, on, off
    • Nulls: null or ~
    • Dates/Timestamps: 2023-10-27, 2023-10-27T10:30:00Z (ISO 8601 format)
  4. Comments: Lines beginning with a # are comments and are ignored by the parser.

    # This is a comment
    setting: value # This is an inline comment
  5. Indentation:

    • Crucial! Indentation (using spaces, not tabs) defines the structure.
    • The number of spaces for indentation must be consistent within the same block. Two spaces are a common convention.
tip
  • Consistent Indentation: Use spaces, not tabs. The most common convention is 2 spaces per indent level. Be consistent throughout your file.

  • Validate Your YAML: Use a YAML linter or validator (many online tools and IDE extensions are available) to catch syntax errors early. This is especially helpful when you're starting out.

  • Quoting Strings:

    • Strings don't always need quotes. However, quote strings if they:
      • Contain special characters (e.g., :, {, } or others).
      • Start with a character that could be misinterpreted as another type (e.g., true, false, null, numbers, yes, no).
      • Need to preserve leading/trailing whitespace.