YAML: human-readable, parser-strict
YAML (recursive acronym for "YAML Ain't Markup Language") was born in 2001 as an XML alternative for configs. Big idea: use indentation instead of braces or brackets to denote hierarchy. The result reads like a bullet list rather than code. That's why Kubernetes, Docker Compose, GitHub Actions, GitLab CI, Ansible and most modern devops tools use it.
Why convert to JSON
- JavaScript processing. Browsers parse JSON natively; YAML needs an external library of several KB.
- APIs. Almost every REST API speaks JSON. If your config is YAML, you must convert.
- Validation with existing tools. JSON Schema is mature; YAML equivalents are less common.
- Version diffs. YAML diffs can be misleading because of indentation; minified JSON diffs are always clear.
Typical use cases
- Inspecting a Kubernetes manifest. Convert to JSON to view it in an API tool or run jq over it.
- Migrating config to a JSON-only system. Plenty of legacy still expects JSON.
- Test snapshots. Snapshotting structures as JSON is easier in testing.
- Posting to a REST endpoint. Some APIs accept YAML but most don't.
Limitations of this converter
It supports the most common syntax that covers 95% of cases: scalars (strings, numbers, booleans, null), hyphen-prefixed lists, nested maps with colons, and # comments. It does NOT support advanced YAML features like anchors (&), aliases (*), custom tags (!!str), multi-document streams (---) or mixed flow style. For those cases, use a full library like js-yaml.
Common YAML traps
- Tab indentation. YAML allows only spaces. Mixing tabs and spaces breaks the parser.
- Accidental booleans. "yes", "no", "on", "off", "y", "n" are parsed as booleans. To keep the literal string, quote it.
- Numbers that look like strings. "012" is parsed as octal in YAML 1.1 — quote it.
- The "Norway problem." Norway's ISO code is "NO" and YAML turns it into false. Famous saga:
countries: [NO, NL]ends up as[false, "NL"].
YAML vs JSON: which to use
For config a human will hand-edit, YAML is more readable. For data flowing between machines, JSON is stricter and faster to parse. Good practice: write configs in YAML but compile to JSON at build time and serve JSON in production. Cuts surprises from ambiguous types and improves parser performance.
Security tips
YAML has a complicated security history: it can execute arbitrary code via tags if the parser supports it (CVEs in Ruby psych, Python pyyaml). When parsing untrusted YAML, use a "safe" loader that only allows basic types. This converter never executes code under any circumstances.