Skip to main content
In this lesson we introduce YAML and show how it compares with other common data-serialization formats. If you’ve worked with XML or JSON before, many concepts will feel familiar; if not, follow the examples and try them locally to build intuition. YAML (YAML Ain’t Markup Language) is a human-friendly data-serialization format commonly used for configuration files, CI/CD pipelines, Kubernetes manifests, and other structured data. Quick side-by-side example Below is the same small dataset represented in XML, JSON, and YAML so you can quickly compare readability and conciseness. XML
JSON
YAML
Take a moment to compare the three: YAML is intentionally concise and optimized for human readability. Comparison at a glance Basic key-value pairs A YAML key-value pair uses a colon to separate the key and value. For readability and to avoid parsing issues, put a space after the colon.
Lists (arrays) Represent lists with a dash (-) before each item. Leave a space after the dash.
Mappings / dictionaries Group related keys under a single parent key by indenting the nested properties.
Indentation and spacing Indentation defines structure in YAML. Use a consistent indentation style (2 spaces per level is common) and never mix tabs and spaces. Incorrect indentation can change parse results or produce errors. In the example below, Fat and Carbs are indented incorrectly so they appear to be children of Calories — which is invalid because Calories already has a scalar value. Incorrect (invalid)
This typically triggers errors like “mapping values are not allowed here” because a node cannot be both a scalar and a mapping at the same time. Keep the same indentation level for sibling properties.
Use a consistent indentation style (2 spaces per level is common). Avoid mixing tabs and spaces. Consistent indentation prevents unexpected nesting and parser errors.
Always put a space after the colon (Key: Value) and after the dash in list items (- item). Omitting these spaces can cause subtle parsing errors in some YAML parsers.
Nested structures (lists of mappings, mappings with lists) YAML can express arbitrarily nested structures. The example below shows a list of fruits where each item is a mapping containing nutritional properties.
Notes about this structure:
  • Fruits is a key whose value is a list.
  • Each list element (- Banana: and - Grape:) is a mapping with its own nested keys (Calories, Fat, Carbs).
Common YAML constructs Best practices and tips
  • Use consistent indentation (2 spaces per level recommended).
  • Always use a space after colons and dashes.
  • Prefer explicit quoting for values that could be interpreted (e.g., yes, no, on, off, numeric strings).
  • Validate YAML with a linter or parser before applying it to production systems (CI checks are helpful).
  • When authoring large files, split logical sections into separate files and reference them where supported (e.g., Kubernetes manifests with kustomize or Helm values).
Summary
  • YAML is a concise, human-readable format for structured data and configuration.
  • Use key: value pairs, - for lists, and indentation to create nested structures.
  • Be consistent with spacing and indentation to avoid parser errors.
Links and references

Watch Video

Practice Lab