YAML Configuration Cheatsheet

Quick reference for YAML: syntax, data types, collections, anchors, multiline strings, and common patterns.

FeatureDescriptionExampleCategory
Key-Value PairBasic key-value syntaxname: John Doe age: 30 city: New YorkBasics
CommentsSingle-line comments# This is a comment name: John # Inline commentBasics
Document SeparatorSeparate multiple documents--- doc: 1 --- doc: 2Basics
Document EndMark end of documentname: John ...Basics
StringString values (quotes optional)name: John title: "Lead Developer" quote: 'Single quotes'Scalars
NumberInteger and float valuesage: 30 pi: 3.14159 scientific: 1.23e+10Scalars
BooleanBoolean true/false valuesenabled: true active: false yes_val: yes no_val: noScalars
NullNull/empty valuesmiddleName: null empty: ~ nothing:Scalars
Date/TimeDate and timestamp valuesdate: 2024-01-15 timestamp: 2024-01-15T10:30:00ZScalars
List (Flow)Inline list notationcolors: [red, green, blue] numbers: [1, 2, 3, 4]Collections
List (Block)Block-style listfruits: - apple - banana - orangeCollections
Dictionary (Flow)Inline dictionaryperson: {name: John, age: 30, city: NYC}Collections
Dictionary (Block)Block-style dictionaryperson: name: John age: 30 city: NYCCollections
Nested CollectionsLists and dicts combinedusers: - name: John role: admin - name: Jane role: userCollections
Literal Block (|)Preserve newlines and formattingdescription: | This is line 1 This is line 2 Newlines preservedMultiline
Folded Block (>)Fold newlines into spacestext: > This long text will be folded into one lineMultiline
Literal ChompingControl trailing newlineskeep: |+ text strip: |- textMultiline
Anchor (&)Define reusable nodedefaults: &defaults timeout: 30 retries: 3Anchors
Alias (*)Reference anchored nodedev: <<: *defaults env: developmentAnchors
Merge Key (<<)Merge anchored valuesbase: &base x: 1 child: <<: *base y: 2Anchors
Multiple MergesMerge multiple anchorsconfig: <<: [*defaults, *common] name: appAnchors
Explicit TypesForce data typenumber: !!str 123 boolean: !!str true list: !!seq [1, 2, 3]Advanced
Complex KeysNon-scalar keys? [complex, key] : value ? {name: John} : person_dataAdvanced
Set TypeUnique unordered valuesunique: !!set ? item1 ? item2 ? item3Advanced
Ordered MapPreserve key orderordered: !!omap - first: 1 - second: 2 - third: 3Advanced
Docker ComposeDocker compose exampleversion: '3.8' services: web: image: nginx:latest ports: - "80:80"Advanced
CI/CD PipelineGitHub Actions examplename: CI on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2Advanced
KubernetesK8s pod configurationapiVersion: v1 kind: Pod metadata: name: myapp spec: containers: - name: app image: myapp:1.0Advanced