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
&baseand*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
!!strare honored.!!intand!!floatensure correct typing in the JSON output. - Multiline strings.
|-style block scalars become regular JSON strings with\nescapes. Round-trip back to YAML and you get the same block style. - Booleans. We default to YAML 1.2 strict booleans (
true/falseonly). Older configs may expectyes/noto 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?
Does it preserve comments?
What YAML version is supported?
&ref / *ref), block and flow styles, multiline strings (| literal, > folded), explicit tags.Why does <code>NO</code> become <code>false</code> in my JSON?
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?
| 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?
yq for streaming.Related tools
Last updated: 2025-01-15