YAML (YAML Ain't Markup Language)
A human-readable data serialization standard that is often used for configuration files and applications where data is being written by humans.
YAML is designed for maximum human readability. It uses indentation (whitespace) to denote structure instead of brackets and braces, making files look clean and less cluttered. It is a superset of JSON, which means that any valid JSON file is also a valid YAML file.
Because of its simplicity, YAML is commonly used in DevOps and software development for defining configuration files, especially in tools like Docker Compose, Kubernetes manifests, GitHub Actions, CircleCI, and Ansible.
Key Features of YAML
- Readability: Minimalist syntax makes YAML easier to read and edit by humans compared to XML or even JSON.
- Comments: Lines starting with
#
are considered comments and ignored during parsing. - Data Structures: Natively supports complex data structures like nested objects (maps), lists (sequences), and simple values (scalars).
- Multi-Document Support: YAML can include multiple documents within a single file, separated by
---
. - Aliases and Anchors: Advanced referencing features like anchors (
&
) and aliases (*
) to reuse configuration blocks. - Flexible Typing: Supports booleans, integers, floats, strings, and null values out of the box.
Example YAML
name: MyApp
version: 1.0.0
dependencies:
http: ^0.13.0
flutter:
sdk: flutter
scripts:
build: flutter build apk
start: flutter run
This sample shows how YAML is used to define dependencies and scripts in a Flutter or Dart project. Its clean layout makes it easier to manage manually compared to equivalent JSON.
Despite its benefits, YAML can be error-prone due to its sensitivity to whitespace. It's recommended to use proper linters or validators when writing large YAML files.