YAML Validator
Validate YAML syntax and convert to JSON. Common YAML config and Kubernetes manifest checker.
What is YAML?
YAML (YAML Ain’t Markup Language) is a human-readable data serialization format used primarily for configuration files. It’s the configuration language of modern DevOps and cloud infrastructure: Kubernetes manifests, Docker Compose, GitHub Actions, GitLab CI, Ansible playbooks, CircleCI, Travis CI, Helm charts, all use YAML. Compared to JSON: YAML is more concise (no braces/brackets, uses indentation), supports comments, easier to read for humans. Compared to XML: way less verbose. But YAML’s indentation-based syntax is also its weakness – one wrong space breaks everything. This validator catches syntax errors instantly and converts to JSON for verification.
How to use this tool
- Paste YAML content — Configuration file, Kubernetes manifest, GitHub Actions workflow, etc.
- Read validation status — Green checkmark = valid YAML. Red error = syntax issue with specific line/column.
- View JSON equivalent — Tool converts valid YAML to JSON – useful for debugging or feeding YAML data to JSON-only tools.
- Copy JSON if needed — Use the converted JSON in your app or share with collaborators.
YAML syntax rules
Basic structure:
name: MavexTech version: 1.0 tools: - calculator - converter config: free: true signup: false
Key rules:
- Use SPACES, never tabs (most common bug)
- Indentation is significant – consistent spacing matters
- Colon followed by space separates key from value
- Lists use dash + space
- Strings usually unquoted, quote if contains special characters
- Comments start with #
- Three dashes (—) separate multiple documents in one file
vs JSON:
- YAML: indentation, no braces, supports comments
- JSON: braces/brackets, strict, no comments
- YAML can express same data as JSON, plus more (anchors/references, types)
Examples
Kubernetes deployment:
apiVersion: apps/v1 kind: Deployment metadata: name: mavex-app spec: replicas: 3
Docker Compose:
version: '3.8'
services:
web:
image: nginx
ports:
- 80:80GitHub Actions workflow:
name: CI
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3Tips & best practices
- ALWAYS use spaces, never tabs – this is the #1 YAML bug source
- Use 2-space indentation consistently (most projects’ standard)
- Quote strings containing colons (URLs, IPs) to prevent parsing as key:value
- Multi-line strings: use | (preserve newlines) or > (fold to single line)
- Anchors and aliases (&name and *name) for DRY config – reduce duplication
- Comments explain non-obvious config decisions – YAML supports # comments
- Editor with YAML support (VSCode, IntelliJ) catches errors as you type
Limitations & notes
Browser-side YAML parsing uses js-yaml library – supports YAML 1.2 spec. Doesn’t validate against schemas (Kubernetes, etc) – just basic syntax. For schema-aware validation, use dedicated tools like kubeval, json-schema validators with YAML→JSON conversion. The output JSON is valid but may have format differences (key order, types) from manual JSON.
Frequently Asked Questions
Why does my YAML break with ‘mapping not allowed’ error?
Inconsistent indentation – mixing tabs and spaces, or different indent levels. ALWAYS use only spaces, consistent count throughout (typically 2 spaces). Configure your editor to show whitespace – makes invisible tabs visible.
Can I use tabs in YAML?
NO – YAML spec forbids tabs as indentation. Many YAML files break because someone copy-pasted indented code that contained tabs. Configure editor to convert tabs to spaces automatically.
What’s the difference between YAML and JSON?
Same data can be expressed in both. YAML: more concise, supports comments, indentation-based, harder to debug. JSON: more verbose, no comments, strict syntax, easier to validate. JSON is more popular for APIs; YAML dominates configuration.
Why isn’t my Kubernetes manifest working?
Common YAML issues: tabs vs spaces, missing space after colon, incorrect indentation level. The tool catches these. For Kubernetes-specific validation (correct API versions, required fields), use kubeval or kubectl apply –dry-run.
What is a YAML anchor and alias?
Reusability feature. Define once with &name, reference elsewhere with *name. Reduces duplication. Example: define common settings with &defaults, then apply to multiple sections with <<: *defaults.
Can YAML handle multi-line strings?
Yes – two operators. | preserves line breaks (good for code, scripts). > folds to single line with spaces. Both indented relative to the parent key.
How do I include another YAML file?
YAML itself doesn’t have includes. Use templating tools (Helm, Kustomize for Kubernetes) or pre-processing (envsubst). Or split into multiple YAML documents with — separator.
