All guides
Term

YAML

A human-readable data serialization language used for configuration files and data exchange between programming languages.

YAML (YAML Ain't Markup Language) is a human-readable data serialization language used primarily for configuration files and data exchange between programming languages. Unlike JSON or XML, it minimizes structural characters such as braces, brackets, and quotation marks in favor of clean indentation. Because YAML is a strict superset of JSON, any valid JSON document is also valid YAML, allowing systems to parse both formats smoothly.

How it works

YAML defines data hierarchy through consistent whitespace indentation rather than enclosing delimiters. It relies on three foundational data primitives to represent complex structures:

  • Scalars: Individual values such as strings, integers, floating-point numbers, and booleans.
  • Sequences: Ordered lists where each item is prefixed by a hyphen and a space.
  • Mappings: Unordered key-value pairs separated by a colon and a space.

Beyond basic structures, YAML supports inline comments (prefixed with #), multi-line text blocks, explicit data typing, and reusable variables called anchors and aliases. These features make it the standard configuration format across DevOps and cloud hosting ecosystems, including Kubernetes manifests, Docker Compose files, Ansible playbooks, and CI/CD pipelines like GitHub Actions.

Example

The following snippet demonstrates a standard Docker Compose configuration file (docker-compose.yml) using mappings, sequences, scalars, and comments to define a web application stack:

# Define application services
services:
  web:
    image: nginx:alpine
    ports:
      - "8080:80"
    environment:
      APP_ENV: production
      DEBUG: false
    volumes:
      - ./html:/usr/share/nginx/html:ro

What matters when choosing a server or hosting

YAML itself is a lightweight text format, so storing or parsing it requires negligible disk space and minimal CPU overhead during deployment. However, the orchestration tools that consume YAML files—such as Kubernetes or container runtimes—impose specific infrastructure requirements:

  • Orchestration compatibility: Managed container platforms and Platform-as-a-Service (PaaS) providers often require specific YAML schemas for deployment blueprints. Ensure your hosting provider supports the exact API versions used in your manifests.
  • Control plane resources: Self-hosting YAML-driven orchestrators like Kubernetes demands dedicated RAM and CPU for the control plane to continuously reconcile the desired state defined in your files against live server resources.
  • GitOps integration: Look for hosting environments with native Git repository webhooks, allowing changes pushed to your YAML configuration files to trigger automated zero-downtime deployments.

Common mistakes

  • Using tabs instead of spaces: The YAML specification strictly forbids tab characters for indentation. Mixing tabs and spaces will cause immediate syntax errors in parsers.
  • Inconsistent indentation levels: Aligning child keys improperly alters the data hierarchy or breaks parsing entirely. Stick to a uniform standard, typically two spaces per nested level.
  • Unquoted special strings: Certain unquoted words like yes, no, on, or off may be interpreted by older parsers as booleans rather than strings, and values containing colons can break key-value parsing unless wrapped in quotes.

FAQ

Is YAML better than JSON for configuration files?

For human-maintained configuration files, YAML is generally preferred because it supports inline comments, avoids visual clutter, and handles multi-line strings cleanly. JSON remains faster to parse programmatically and is better suited for machine-to-machine API payloads.

Should I use .yaml or .yml as the file extension?

Both extensions are completely valid and parsed identically by standard tools. Using .yaml is the official recommendation, though .yml remains common in legacy systems and specific frameworks.

How do I validate a YAML file before deploying it?

You can catch syntax and indentation errors locally before pushing to a server by running command-line linters such as yamllint or using built-in dry-run flags like kubectl apply --dry-run=client -f config.yaml.

All glossary terms

Glossary

Related terms

Full glossary

New guides every week.

A digest of the best pieces on servers, VPN and self-hosted software. No ads, no spam.

1 email a weekOne-click unsubscribeRU · EN
Only slipjar.app articles, nothing else.