JSON to YAML
Convert JSON to clean, readable YAML.
Overview
The JSON-to-YAML converter rewrites a JSON document into YAML 1.2 syntax. Indentation replaces braces, scalar values stay as scalars, and arrays use the dash-prefix block style for readability.
YAML is the lingua franca of modern config — Kubernetes manifests, GitHub Actions workflows, OpenAPI specs, and Helm values files all live in YAML. Developers migrating config from a JSON source, generating YAML from a typed builder, or just preferring the indented style use a json to yaml converter to switch formats cleanly.
How it works
YAML 1.2 is a superset of JSON, but the idiomatic block syntax looks very different. The converter walks the JSON tree and emits indented block-style YAML: objects become key: value lines, arrays use - item blocks, and nested structures bump the indent by two spaces. Strings are quoted only when needed — when they look like booleans (yes, no), numbers, or contain characters with YAML special meaning (:, #, - at line start).
Long strings can wrap as | (literal block scalar with newlines preserved) or > (folded scalar where line breaks collapse to spaces). The default behaviour quotes when in doubt, which keeps the output safe from YAML's notorious type-coercion footguns.
Examples
Input:
{ "name": "Alice", "tags": ["admin","ops"], "address": { "city": "Berlin" } }
Output:
name: Alice
tags:
- admin
- ops
address:
city: Berlin
Input with risky string:
{ "yes_means": "yes", "version": "1.0" }
yes_means: "yes"
version: "1.0"
FAQ
Why are some strings quoted?
YAML's type rules can coerce yes, no, on, off, null, 1.0, 1e2, and similar tokens to booleans, nulls, or numbers. The converter quotes any string that would otherwise be misinterpreted, following the safest interpretation of YAML 1.2.
Can it produce flow style (inline) YAML?
Block style is the default because it's more readable. Flow style ({ key: value, ... }) is opt-in for cases where you want compact one-line output.
Does it preserve key order?
Yes — keys appear in the same order as the JSON source. Sorting is opt-in via the --sort-keys toggle.