YAML Validator - Validate, Format & Convert YAML Online
How to Use the YAML Validator
Paste your YAML content into the input area and click Validate to check for syntax errors. The validator reports errors with specific line numbers and descriptions. Use Format YAML to normalize indentation to 2 spaces per level. Click Convert to JSON to see the parsed JSON equivalent with syntax highlighting. Copy buttons are available for both the YAML input and JSON output.
Understanding YAML Syntax
YAML (YAML Ain’t Markup Language) is a data serialization format designed for human readability. It represents data through indentation-based structure rather than delimiters like braces or brackets. This makes YAML files clean and easy to scan, but it also means that whitespace errors can break an entire file.
Key-Value Pairs
The fundamental YAML structure is the key-value pair, written as key: value with a colon and space separating the key from the value. Values can be strings, numbers, booleans, null, or nested structures. Strings do not require quotes unless they contain special characters like colons, brackets, or leading spaces.
Lists and Sequences
Lists in YAML are denoted with a dash and space (- ) before each item. List items must be at the same indentation level. Lists can contain simple values, nested mappings, or even other lists. This flexibility makes YAML suitable for complex configuration hierarchies.
Nested Objects
Nesting in YAML is controlled entirely by indentation. Child keys are indented further than their parent. Every sibling at the same level must use identical indentation. Mixing indentation levels within a block is the most common source of YAML parsing errors.
Where YAML Is Used
Docker Compose
Docker Compose files (docker-compose.yml) define multi-container applications using YAML. Services, networks, volumes, and environment variables are all specified through nested YAML structures. A single indentation error in a Compose file will prevent containers from starting.
Kubernetes Manifests
Kubernetes uses YAML extensively for resource definitions: pods, deployments, services, configmaps, and more. Kubernetes manifests are often deeply nested with strict schema requirements. Validating YAML syntax before applying manifests with kubectl apply prevents deployment failures.
CI/CD Pipelines
GitHub Actions, GitLab CI, CircleCI, and many other CI/CD platforms use YAML for pipeline definitions. Workflow files define triggers, jobs, steps, and environment variables in YAML format. Syntax errors in CI/CD YAML can silently break entire build and deployment pipelines.
Configuration Files
Many applications and frameworks use YAML for configuration: Ruby on Rails (database.yml), Ansible playbooks, Spring Boot (application.yml), Jekyll, Hugo, and others. YAML’s support for comments makes it particularly suitable for configuration files that need inline documentation.
Common YAML Mistakes
Tabs instead of spaces: YAML strictly requires spaces for indentation. Tabs will cause a parse error. Configure your editor to insert spaces when the Tab key is pressed for YAML files.
Inconsistent indentation: If one block uses 2 spaces and another uses 4, the parser may misinterpret the structure. Use the Format button in this tool to normalize all indentation to 2 spaces.
Missing space after colon: key:value is invalid. YAML requires a space after the colon: key: value. This also applies to list items: - item needs the space after the dash.
Unquoted special characters: Values containing colons, brackets, or other YAML-special characters must be quoted. For example, message: Note: this is important will be parsed incorrectly because of the second colon. Use quotes: message: "Note: this is important".
Duplicate keys: YAML allows duplicate keys syntactically, but the behavior is undefined. Most parsers silently use the last value, which can lead to subtle configuration bugs.
Related Tools
- JSON-YAML Converter - Convert between JSON and YAML formats
- JSON Formatter - Format and validate JSON data
Frequently Asked Questions
What is the difference between YAML and JSON?
YAML and JSON are both data serialization formats, but they differ in syntax and use cases. YAML uses indentation to represent structure and supports comments, making it more human-readable and ideal for configuration files. JSON uses braces and brackets, is natively supported in JavaScript, and is the standard format for APIs and data exchange. YAML is a superset of JSON, so valid JSON is technically valid YAML. Most developers prefer YAML for configuration (Docker Compose, Kubernetes, CI/CD) and JSON for data interchange.
Why is my YAML invalid?
The most common YAML errors are indentation problems. YAML requires spaces (never tabs) for indentation, and every level must use the same number of spaces consistently. Other frequent mistakes include missing colons after keys, incorrect list formatting (forgetting the space after the dash), unquoted strings that contain special characters like colons or brackets, and duplicate keys. This validator reports the exact line number and nature of each error.
How many spaces should YAML indentation be?
YAML does not mandate a specific number of spaces, but 2 spaces per indentation level is the widely accepted convention used by Kubernetes, Docker Compose, GitHub Actions, and most YAML-based tools. Some projects use 4 spaces. The critical rule is consistency: every level in a single file must use the same indentation width. This tool's Format button normalizes indentation to 2 spaces.
Can YAML have comments?
Yes, YAML supports single-line comments starting with the hash symbol (#). Comments can appear on their own line or at the end of a line after the value. Multi-line comments are not natively supported, but you can use consecutive single-line comments. JSON does not support comments at all, which is one reason many configuration formats prefer YAML.
How do I convert YAML to JSON?
Paste your YAML into this tool and click the Convert to JSON button. The tool parses the YAML structure and produces the equivalent JSON output with syntax highlighting. This is useful when you need to use YAML-defined configuration in a JSON-only context, or when debugging YAML by inspecting its parsed structure.