Skip to content
TypeParser
All tools

YAML ↔ JSON

Convert between YAML and JSON.

beats onlineyamltools.com edge: Auto-detect direction + indent control
input
output
direction indent
paste to convert
Guide

About YAML ↔ JSON

Bidirectional YAML ↔ JSON conversion that auto-detects which direction to go from the input. Validates as it parses, so you get a precise error before any conversion. Indent control on YAML output (2 / 4 spaces). Comments are preserved through round-trips when the source format supports them.

When to use which

YAML is human-readable. JSON is machine-parseable. Most config in 2025 starts as YAML (Kubernetes manifests, GitHub Actions, Docker Compose, Ansible) and gets converted to JSON inside tooling for processing. Round-tripping between the two is a daily move.

Conversion details that matter

  • Anchors and aliases. YAML lets you reuse blocks via &base and *base. JSON has no such concept — anchors get inlined, aliases get expanded into copies. The result is more verbose JSON but identical semantics.
  • Tags. Explicit YAML tags like !!str are honored. !!int and !!float ensure correct typing in the JSON output.
  • Multiline strings. |-style block scalars become regular JSON strings with \n escapes. Round-trip back to YAML and you get the same block style.
  • Booleans. We default to YAML 1.2 strict booleans (true/false only). Older configs may expect yes/no to parse as boolean — toggle YAML 1.1 mode for that.

Common workflows

Inspect a Kubernetes manifest. Paste the YAML, see the JSON. The JSON form is what kubectl actually sends — useful for debugging.

Translate a Compose file. Docker Compose v3 is YAML; many tools want JSON. Paste, copy the JSON, feed it forward.

Convert config snippets in PRs. Copy the YAML from a code review comment, see what fields it actually populates. Faster than running the full validation pipeline.

Sanity-check generated YAML. A code generator emits YAML; round-trip it through JSON and back. The two YAMLs should be value-equivalent — if not, the generator is producing something the parser does not see.

Why our converter avoids the YAML 1.1 trap

The classic YAML footgun: country: NO parses as country: false. The Norwegian Country Code Catastrophe. Our default is YAML 1.2 — NO stays a string. If you genuinely need the old behavior (legacy Ansible, old Compose files), the toggle is one click away. Most modern YAML is 1.2-or-stricter; defaulting accordingly avoids the most common bug.

Frequently asked questions

How is direction auto-detected?
We try parsing as YAML first (it is a superset of JSON for our purposes). If the input is valid JSON, we convert to YAML; otherwise we treat it as YAML and convert to JSON. You can pin direction with the toggle.
Does it preserve comments?
YAML supports comments; JSON does not. YAML → JSON drops comments. JSON → YAML inserts them only if you provide a hint (we do not invent commentary). For round-trip preservation, edit YAML directly.
What YAML version is supported?
YAML 1.2 (the modern spec). Includes anchors and aliases (&ref / *ref), block and flow styles, multiline strings (| literal, > folded), explicit tags.
Why does <code>NO</code> become <code>false</code> in my JSON?
YAML 1.1 (the older spec, still common) treats YES, NO, ON, OFF as booleans. We default to YAML 1.2 (only true/false are booleans) — toggle YAML 1.1 mode if your input depends on the older behavior.
Can it format multiline strings?
Yes. Block scalars (| for newline-preserving, > for folded) survive round-trips and are emitted by default for any string containing newlines longer than a threshold.
How does it handle big YAML files?
Parsing runs on a Web Worker. Files in the 1-10 MB range convert instantly. Above that, prefer command-line yq for streaming.

Related tools

Last updated: 2025-01-15