WW Tools

YAML ↔ JSON Converter

Convert between YAML and JSON in both directions, plus a YAML reformat that keeps comments, anchors, and multi-document streams.

Converted output appears here

About YAML ↔ JSON Converter

Developers convert between YAML and JSON all day: Kubernetes manifests, Docker Compose files, GitHub Actions workflows, Ansible playbooks, Helm values. Most online converters split the two directions across separate, ad-heavy pages, and they quietly strip comments and anchors even when all you wanted was to tidy a YAML file. This converter goes both ways on one screen with a swap button, updates live as you type, and runs entirely in your browser, so your config never leaves the machine, which matters when the file holds secrets or internal hostnames. It adds a third mode, Reformat YAML, built on the eemeli/yaml Document engine. Reformatting reindents and tidies your YAML while keeping your # comments and your &anchor / *alias / << merge keys intact. Most tools lose those on a reformat; this one does not. There is one boundary worth knowing: JSON has no comment syntax, so converting YAML to JSON cannot carry comments into the JSON output. That is a property of the JSON format, not a bug, and it is exactly why comment preservation lives in the Reformat YAML mode rather than the JSON conversion. The tool also handles multi-document YAML streams separated by --- : it reads them into a JSON array and can split a JSON array back into separate documents. You control JSON indent and minify, YAML indent and block-versus-flow style, optional alphabetical key sorting, and anchor preserve-versus-expand on reformat. Parse errors show the exact line and column so you can find the broken indentation fast.

How to use the YAML ↔ JSON Converter

  1. Pick a direction: YAML → JSON, JSON → YAML, or Reformat YAML.
  2. Paste your config, or drag a .yaml / .yml / .json file onto the input box.
  3. The converted output appears instantly on the right. There is no submit button.
  4. For YAML → JSON set the indent, minify, or sort keys; for JSON → YAML set indent, flow style, or split arrays into documents.
  5. In Reformat YAML, keep "Expand anchors" off to preserve comments and references, or turn it on to inline them.
  6. Copy the result or download it as a .json or .yaml file.

Common Use Cases

Feed a Kubernetes manifest to a JSON-only tool

Convert a k8s YAML manifest to JSON when an API, validator, or linter only accepts JSON. Multi-document manifests become a clean JSON array.

Tidy YAML without losing comments or anchors

Reindent a messy config to a consistent 2- or 4-space style while keeping every # comment and &anchor / *alias / << merge in place, thanks to the eemeli/yaml Document engine.

Flatten or split multi-document streams

Turn a --- separated YAML stream into a single JSON array, or split a top-level JSON array back into separate YAML documents.

Debug a broken config fast

When YAML fails to parse, the inline error points at the exact line and column so you can fix the indentation or a quoting gotcha without guessing.

Frequently Asked Questions

Does converting YAML to JSON lose my comments?

Yes. JSON has no comment syntax, so comments cannot be stored in JSON output. That is a limitation of the JSON format itself, not of this tool. If you want to keep comments, use the Reformat YAML mode, which tidies your YAML while leaving every # comment in place.

Are YAML anchors and aliases preserved?

When converting to JSON, anchors, aliases, and << merge keys are resolved into their concrete values because JSON has no reference syntax. In Reformat YAML with "Expand anchors" off (the default), &anchor, *alias, and << are kept verbatim. Turn "Expand anchors" on to inline them, though that drops comments, which is why it is off by default.

Is converting JSON to YAML lossless?

Yes, for data. Every JSON value has a direct YAML equivalent and YAML is a superset of JSON, so no information is lost going from JSON to YAML. You can choose indent width, block or flow style, and whether to sort keys.

How do I convert a multi-document YAML file (---) to JSON?

Paste the whole stream into YAML → JSON; each document becomes one element of a JSON array, and a badge shows the document count. To go the other way, enable "Split array into documents" in JSON → YAML and a top-level JSON array is written back as separate --- documents.

Is this converter safe for private or sensitive config data?

Yes. Every conversion runs in your browser with no network calls, so nothing is uploaded to a server. You can paste manifests containing secrets, tokens, or internal hostnames and the data stays on your machine.

Why does my YAML break when I convert it?

Usually it is indentation, a tab where spaces are required, or an unquoted value YAML reads as a boolean or number (the classic "Norway problem" where no becomes false). The parser reports the exact line and column of the error so you can find and fix the offending line.