YAML to JSON
Convert between YAML and JSON formats
About YAML to JSON
Converts YAML to JSON, or JSON back to YAML, as you type, using the js-yaml library and 2-space indentation in both directions. When writing YAML, strings that could be misread, such as 'yes' or '123', are quoted automatically, and YAML syntax errors report the line and column where parsing stopped. Useful for Kubernetes manifests, GitHub Actions workflows and docker-compose files.
Category: Encoding.
Frequently asked questions
What are common YAML pitfalls?
▾
Tabs for indentation (YAML only allows spaces) and unquoted values that change type: version: 1.10 becomes the number 1.1, 01234 loses its leading zero, and a date like 2024-01-15 becomes a full ISO timestamp. js-yaml follows YAML 1.2, so yes, no, on and off stay strings; quote any value you need to keep as text.
Does it support multiple documents and anchors?
▾
Anchors (&), aliases (*) and merge keys (<<) are supported and expanded, so the JSON contains the resolved values. A stream with several documents separated by --- is rejected with an error, so convert each document on its own.
Does YAML support comments?
▾
Yes. Lines starting with # are comments. Note that converting YAML to JSON discards all comments, since JSON has no comment syntax.
Is YAML a superset of JSON?
▾
In practice, yes: YAML 1.2 was designed so that valid JSON is also valid YAML, so you can paste JSON on the YAML side to reformat it. One exception here: js-yaml rejects duplicate keys, which JSON.parse() silently accepts.