Conversion guide
JSON to YAML: Convert Config and Data Files
Convert JSON to YAML for config files, Kubernetes manifests, and CI pipelines. Step-by-step examples with multiline strings, comments, and edge cases.
YAML is the lingua franca of Kubernetes manifests, GitHub Actions workflows, Docker Compose files, and most modern dev tooling. When your data is in JSON — straight out of an API or generator — you need a reliable way to render it as YAML without losing structure. This guide walks through the conversion, edge cases, and how to keep the result readable.
Paste your JSON into the JSON to YAML converter for a one-click conversion, or read on to see how to handle nested objects, arrays, and multiline strings.
TL;DR
YAML is a superset of JSON 1.2, so every JSON document is technically valid YAML. The point of converting JSON to YAML is readability: nested keys become indentation, arrays become dashed lists, and long strings can wrap across lines. Two-space indentation, no tabs, and quote any string that looks like a number or boolean.
Step 1 — Flat object to block style
The simplest case: a JSON object becomes a list of key: value pairs.
Input
{
"service": "acme-api",
"replicas": 3,
"image": "acme/api:1.2.0"
}
Output
service: acme-api
replicas: 3
image: acme/api:1.2.0
Notice the value acme-api is unquoted — it's a plain string. The number 3
stays a number. If the value is yes, no, true, false, or null, YAML
will interpret it as a boolean or null; quote it to keep it a string.
Step 2 — Nest with indentation
Nested JSON objects become indented blocks. Each level adds two spaces. Tabs are not allowed — most YAML parsers reject them.
Input
{
"service": "acme-api",
"env": {
"NODE_ENV": "production",
"LOG_LEVEL": "info"
}
}
Output
service: acme-api
env:
NODE_ENV: production
LOG_LEVEL: info
For deeply nested structures, the indentation grows linearly. If readability suffers past three levels, consider flattening with the JSON flatten tool before converting.
Step 3 — Arrays as dashed lists
JSON arrays become YAML sequences with a - prefix per element.
Input
{
"service": "acme-api",
"ports": [80, 443, 8080],
"tags": ["api", "production", "v1"]
}
Output
service: acme-api
ports:
- 80
- 443
- 8080
tags:
- api
- production
- v1
Arrays of objects nest the dashes one level deeper, with the first key of each
object on the same line as the -:
containers:
- name: api
image: acme/api:1.2.0
- name: worker
image: acme/worker:1.2.0
Step 4 — Handle multiline and special strings
Long strings — like a SQL query, an env-loaded script, or a JSON-encoded config
— render poorly on one line. YAML's block scalars (| literal, > folded) keep
them readable.
Input
{
"startup_script": "#!/bin/bash\nset -e\necho 'starting'\nexec /app/bin/server"
}
Output
startup_script: |
#!/bin/bash
set -e
echo 'starting'
exec /app/bin/server
The | preserves newlines exactly. Use > if you want lines folded into spaces
(common for long prose descriptions).
Strings that look like numbers or booleans need quotes to stay strings:
version: '1.0' # without quotes, parsed as 1.0 (a float)
enabled: 'yes' # without quotes, parsed as true (YAML 1.1 quirk)
Common conversion problems
"My version number became a float"
version: 1.0 parses as the float 1.0, so 1.10 becomes 1.1. Quote any
version-like string: version: "1.10".
"My YAML lost the boolean meaning"
In YAML 1.1, yes, no, on, off, y, n all parse as booleans. YAML 1.2
narrowed this to true/false, but many parsers (including some Ruby and
Python ones) still ship YAML 1.1 behavior. Quote ambiguous values.
"Indentation is off after conversion"
The converter probably used tabs or inconsistent widths. Two-space indentation, spaces only — that's the safe default for every modern YAML parser.
"The output has anchors I didn't ask for"
Anchors (&id) and aliases (*id) are introduced when a converter detects
repeated subtrees and tries to deduplicate. They're valid YAML but harder to
read. Most tools have a flag to disable them; JSONZen does not emit anchors at
all.
"Comments disappeared on round-trip"
JSON does not have comments. If you started with JSONC or JSON5, the converter discarded them during the JSON parse step before YAML conversion. Add comments after rendering, or use a tool that preserves the JSONC source.
Convert in the browser, no upload
The free JSON to YAML converter on JSONZen runs entirely in your browser. It handles multiline strings, escapes ambiguous keys, preserves key order, and never sends your data to a server — useful when your JSON contains secrets, internal URLs, or anything else that shouldn't leave your machine.
You can also pre-format the JSON with the JSON formatter first if you want to sanity-check the structure before converting.
Closing recommendation
For Kubernetes manifests and CI pipelines, convert JSON to YAML and lean on block style and indentation — that's what humans came to YAML for. For machine-to-machine config exchange where readability doesn't matter, JSON is already valid YAML and you can skip the conversion entirely.
Related guides
- JSON vs YAML: Choosing a Config Format
JSON vs YAML compared on readability, comments, tooling, and gotchas. Concrete examples and a clear recommendation for each common config use case.
- JSON to CSV: Convert Flat and Nested Data
How to convert JSON to CSV including nested arrays and objects. Side-by-side examples, common pitfalls, and a free in-browser tool that handles edge cases.