Back to tools

JSON ↔ YAML

Bridge JSON and YAML without losing data or structure

Modern tooling is split between two data formats: JSON dominates APIs and machine-to-machine traffic, while YAML is the default for configuration files in Docker, Kubernetes, CI pipelines, and Ansible. Switching between them by hand is error-prone because the two grammars differ in subtle ways — YAML accepts unquoted strings and allows comments, JSON requires strict quoting — and a naive conversion can silently corrupt types or nesting. This converter performs a faithful round trip in both directions, so the object you get back is the object you put in.

Use it when you need to hand a JSON API response to a YAML-based tool, port a config file into a JSON-only system, or simply read a dense YAML file as structured JSON.

Convert JSON to YAML in Five Steps

  1. Paste your JSON document into the input panel.
  2. Select the JSON to YAML direction from the converter controls.
  3. Click Convert and inspect the result: objects become indented mappings, arrays become hyphenated lists.
  4. Review the output for quoted strings, which the converter adds only where YAML would otherwise misread a value.
  5. Copy the YAML into your config file, or flip the direction to convert YAML back to JSON.

Real Example: A Service Config in Both Formats

A typical Docker Compose service defined in YAML needs to become JSON for an orchestration API that only accepts JSON. The structure maps one-to-one: the top-level mapping becomes a JSON object, the ports list becomes an array, and scalar values keep their types across the boundary.

YAML InputJSON Output
image: nginx:1.25
ports: [80, 443]
{"image": "nginx:1.25", "ports": [80, 443]}

Round-Trip Safety Tips

When You Need This Converter

Frequently Asked Questions

Is JSON to YAML conversion lossless?

For data, yes: types, nesting, and values are preserved. Comments and document markers from YAML have no JSON equivalent and are dropped when converting to JSON.

Why are some values quoted in the YAML output?

YAML interprets bare scalars like yes, null, or 1.0 as typed values in some parsers. Quoting forces them to stay strings, preserving the original JSON type.

Can I convert a multi-document YAML file?

A file containing multiple documents separated by --- should be split first. The converter handles a single YAML document, which corresponds to a single JSON value.

Why does my YAML use two spaces of indentation?

Two spaces is the dominant convention in Kubernetes, Ansible, and most YAML tooling. The converter emits consistent indentation that any YAML parser accepts.

Does the converter handle nested arrays and objects?

Yes. Arbitrarily deep nesting converts cleanly: mappings become objects, sequences become arrays, and the hierarchy is preserved at every level.

What happens to YAML anchors and aliases?

Anchors (&name) and aliases (*name) are YAML-only features. They are expanded to their full values during conversion, which changes the document shape but not its meaning.

Is YAML a superset of JSON?

Nearly. Every JSON document is valid YAML, but YAML adds features JSON lacks: comments, anchors, multi-line strings, and implicit typing. That asymmetry is why round trips need care.

Which format should I use for a new project?

Use YAML for config files humans edit frequently and JSON for APIs, storage, and anything machine-generated. When in doubt, JSON is the safer, more portable default.