Skip to content
DevTools

YAML to JSON

YAML ⇄ JSON

Convert YAML to JSON and back, anchors and multiple documents included.

yaml
json
Result appears here

Full YAML 1.2: anchors and aliases are resolved, merge keys are applied, block scalars are preserved, and a multi-document file separated by --- becomes a JSON array. Try the sample to see the anchors expand.

About YAML to JSON

Convert YAML to JSON or JSON back to YAML. The usual reason to want this is a Kubernetes manifest, a CI pipeline, or a Docker Compose file that you need to inspect programmatically or paste into something that only speaks JSON.

This uses a full YAML 1.2 parser rather than a simplified one, and the difference shows up immediately on real configuration. Anchors and aliases are resolved, merge keys are applied so a shared block of defaults actually appears in each service that inherits it, block scalars keep their line breaks, and a file containing several documents separated by --- becomes a JSON array. A regex-based converter mishandles all of those, usually without saying so.

Both directions run in your browser. Configuration files are exactly the kind of thing that carries hostnames, bucket names and occasionally a secret, so it is worth knowing none of it is uploaded.

Common questions

Why does my anchor disappear in the JSON?
It has not disappeared — it has been expanded. JSON has no concept of a reference, so an alias is replaced by a copy of what it pointed at. That is the correct conversion, and it is also why converting back to YAML gives you repeated blocks instead of the anchor you started with.
Is JSON valid YAML?
Yes. YAML 1.2 is a superset of JSON, so any JSON document parses as YAML unchanged. That is why the JSON → YAML direction is really a reformat: it produces the indented style people actually want to read.
Why is my unquoted value coming out as a boolean?
The classic YAML trap. In YAML 1.1, which some tools still follow, `yes`, `no`, `on` and `off` are booleans — so a country code of NO becomes false. YAML 1.2 narrowed this to true and false only, which is what is used here. Quote such values regardless; you cannot control which parser reads your file next.
Are comments preserved?
Not through a conversion to JSON, because JSON has nowhere to put them. If you need to keep comments, edit the YAML directly rather than round-tripping it.

This page does the work itself, in this tab. Nothing you paste is sent to a server. Close the tab and no copy remains.