What is YAML?
YAML (YAML Ain't Markup Language) is a human-friendly data serialization format designed for configuration files and data exchange. Unlike JSON, YAML uses indentation instead of braces and brackets to represent structure, making it more readable for complex configurations.
YAML is widely used in DevOps tools like Kubernetes, Docker Compose, Ansible, GitHub Actions, GitLab CI/CD, Helm charts, and many application configuration files like Spring Boot and Rails.
YAML Structure
YAML is built on three core structures:
- Scalars: Simple values like strings, numbers, booleans, and null. Strings don't always need quotes:
name: John Doe
- Sequences (Lists): Ordered collections using
- prefix. Each item starts with a dash and space on a new line.
- Mappings (Dictionaries): Key-value pairs separated by
: followed by a space. Keys are unique within a mapping.
YAML uses consistent indentation (spaces only, not tabs) to denote nesting. The number of spaces per level is flexible but must be consistent within the same block.
YAML vs JSON
YAML is actually a superset of JSON. Every valid JSON document is also valid YAML. Key differences include:
- Readability: YAML uses indentation instead of braces, making deeply nested structures more readable.
- Comments: YAML supports comments with
#, while JSON does not support comments at all.
- Multi-line strings: YAML has
| (literal block) and > (folded block) for multi-line text.
- Data types: YAML auto-detects types.
true, yes, on are all booleans. JSON only recognizes true and false.
- Anchors and aliases: YAML supports
& (anchor) and * (alias) for reusing values, reducing duplication.
YAML Validation Rules
- Indentation must use spaces: Tabs are not allowed. Use 2 or 4 spaces consistently.
- Colons need a space:
key: value is valid, key:value is not.
- Special characters need quoting: Values starting with
*, &, {, [, %, @, or ` must be quoted.
- Consistent indentation: All items at the same level must use the same number of spaces.
- No duplicate keys: Keys within the same mapping must be unique.
- Multi-document separator: Use
--- to separate multiple documents in one file.
Using This YAML Validator
This tool helps you validate YAML online quickly and accurately:
- Validate: Checks if your YAML is syntactically correct and shows detailed error information if not.
- Format: Validates and then pretty-prints your YAML with consistent 2-space indentation.
- YAML → JSON: Converts your YAML to equivalent JSON format, useful for APIs and debugging.
- Copy: Copies the current output content to your clipboard.
- Clear: Clears the input area to start fresh.
When an error is found, you'll see the exact line and column number, plus a description of what went wrong. This makes debugging malformed YAML much easier than reading raw parser errors.