YAML Cheatsheet

YAML syntax, data structures, and best practices for configuration files

Data Format6 commandsbeginner

Overview

YAML is a human-friendly data serialization format for configuration files.

Why It Matters

YAML is widely used for configuration files in Kubernetes, Docker Compose, and CI/CD systems.

Essential Commands

yq . config.yaml

Pretty-print YAML structure

yq ".services.web.image" docker-compose.yml

Read nested YAML value

yq ".version = "3.9"" -i docker-compose.yml

Update field in-place

yamllint config.yaml

Lint YAML file for syntax/style issues

yq -o=json . config.yaml

Convert YAML to JSON

yq ".items[] | .name" data.yaml

Iterate over array values

Quick Start

Start with the use proper indentation and structure

Key Concepts

Use proper indentation and structure

Understand lists, dictionaries, and scalars

Handle special characters and multiline strings

Pro Tips

  • Combine multiple commands for powerful workflows
  • Use aliases to speed up your command entry
  • Create scripts to automate repetitive tasks

Common Pitfalls to Avoid

  • Forgetting to check the documentation for edge cases
  • Running commands without understanding their full impact
  • Not testing changes in a safe environment first

Related Resources

13 items