Skip to content
jsonbeautifiers
English

JSON to YAML

For Kubernetes, Compose and CI files, without sending your config anywhere.

JSON
YAML

Nothing you paste leaves your browser. The connect-src allowlist makes that a browser guarantee rather than a promise. Check it yourself

Convert JSON to YAML for Kubernetes manifests, Docker Compose files, GitHub Actions workflows and anything else that prefers the readable format.

Since YAML is a superset of JSON, this conversion always succeeds. The interesting direction is the other one.

What changes and what does not

Every JSON value has a YAML equivalent, so nothing is lost. Objects become mappings, arrays become sequences, and the quotes around keys and simple strings disappear.

Strings that could be mistaken for something else keep their quotes. That includes the word no, the word yes, anything that looks like a number, and anything that looks like a date. The dumper is conservative about this on purpose, for the reason on the YAML to JSON page.

Large integers

YAML has arbitrary-precision integers, but the value still has to survive JavaScript on the way through. An integer above 2^53-1 is written as a quoted string here so no digits are lost, and the conversion says it did that. Silently emitting a rounded number would be worse.

Line width

Line wrapping is off by default. YAML dumpers traditionally wrap long strings at 80 columns, which is fine for prose and terrible for a URL, a base64 blob or a command line, because the wrapped form is harder to grep and to edit. Unwrapped output is what almost everyone wants.

How to do this in code

Converting in code.

py Python

PyYAML sorts keys by default, which quietly reorders a config file you were trying to convert faithfully.

import json, yaml

data = json.loads(text)
out = yaml.safe_dump(
    data,
    sort_keys=False,        # default is True, which reorders your file
    default_flow_style=False,
    allow_unicode=True,     # otherwise é becomes an escape
    width=10**6,            # effectively no wrapping
)
sh Shell
# yq, the YAML counterpart to jq
yq -P eval . input.json > output.yaml

# Or via Python, with no extra install
python -c 'import sys,json,yaml; yaml.safe_dump(json.load(sys.stdin), sys.stdout, sort_keys=False)' < in.json
js JavaScript
import { dump } from 'js-yaml';

const yaml = dump(JSON.parse(text), {
  lineWidth: -1,    // no wrapping
  noRefs: true,     // no anchors and aliases in the output
});

Questions

Is YAML really a superset of JSON?
YAML 1.2 is, by design. Any valid JSON document is valid YAML. YAML 1.1 was not quite, which is one more reason the version matters.
Why are some of my strings quoted in the output?
Because unquoted they would parse as something else. no, yes, on, off, true, null, a bare number and anything date-shaped all need quotes to stay strings in at least some YAML parsers. The dumper is being careful on your behalf.
Can I keep my comments when converting the other way?
No. JSON has no comment syntax, so a YAML file with comments loses them on the way to JSON, permanently. That is a one-way door worth knowing about before you convert a config file you maintain by hand.