Convert JSON Configs to YAML
Every JSON document is valid YAML — so the conversion cannot lose data. It can, however, misrepresent values: YAML's eager type interpretation turns unquoted yes into true and 1.10 into 1.1. Safe conversion is about the quotes.
Updated 2026-08-06 · ~7 min read
Why these two formats keep meeting
JSON dominates APIs; YAML dominates configuration — Kubernetes, CI pipelines, application settings. Workflows cross that border constantly: an API's JSON output becoming a config starting point, generated manifests, documentation examples moving between formats. The conversion is small; doing it without value corruption is the skill.
The subset relationship, precisely
YAML was designed to include JSON: every valid JSON document parses as YAML 1.2. The practical meaning — conversion from JSON to YAML is lossless by construction. No data disappears, no structure collapses. What can change is representation: how scalars get written, which is exactly where the traps live.
The boolean trap: yes, no, on, off
YAML interprets a roster of bare words as booleans — yes, no, on, off, true, false. A JSON string 'yes' written unquoted into YAML becomes boolean true when parsed back. Configs storing country codes, feature names, or literal answers hit this constantly. Correct conversion quotes any scalar that the YAML parser would reinterpret — and the visible symptom of forgetting is a value that changed type between formats.
The version number trap
The classic: version 1.10 unquoted parses as the float 1.1 — same as 1.10 mathematically, catastrophically different as a version identifier. Anything with leading zeros, multiple dots, or trailing zeros in a numeric-looking string needs quotes. Deployment pipelines have shipped wrong versions over exactly this conversion bug; the check is cheap and the failure is public.
Indentation: YAML's one non-negotiable
YAML structure is indentation — two spaces per level, spaces only, never tabs. JSON carries explicit braces; YAML carries spatial hierarchy, and a single misaligned line silently re-parents a key under the wrong block. Generated output solves this mechanically, which is the quiet argument for converting with a tool instead of retyping: humans mix tabs and spaces; converters do not.
Multi-line strings: the formatting upgrade
One genuine improvement on the JSON-to-YAML direction: multi-line strings. JSON forces escaped newlines inside one line; YAML offers block scalars (the pipe and greater-than markers) that lay the text out naturally. Descriptions, prompts, and certificate blocks become readable in YAML in a way JSON never allows — a real quality gain when configs carry long text.
Verifying conversions that matter
The three-point check for configs headed somewhere important: parse the YAML back and compare against the original JSON (round-trip equality), spot-check every scalar that looks numeric or boolean, and run the target system's own validator when one exists. Kubernetes manifests, for instance, have strict schemas — a conversion that round-trips can still violate a schema, and the schema check catches what conversion cannot.
The reverse direction's asymmetry
YAML to JSON is not the same easy conversion backwards: YAML has features JSON lacks (anchors, comments, multiple documents), so the reverse conversion must resolve or discard them. The asymmetry matters for workflow planning — converting to YAML for editing means accepting that comments and anchors will not survive a return trip.
Local conversion for sensitive configs
Configs carry connection strings, feature flags, and sometimes credentials-in-transit. Local conversion processes them in the browser — and regardless of tool choice, the standing rule applies: real secrets belong in secret managers, not in pasted config text.
Anchors and aliases: features YAML has that JSON cannot express
YAML's anchor syntax lets a block be defined once and referenced multiple times — deduplication that JSON simply cannot represent. Converting JSON to YAML therefore never requires anchors, but after conversion, introducing them by hand can shrink repetitive configs dramatically: a shared defaults block anchored once, aliased into each service entry. The caution: anchors are resolved by the parser, and some restricted YAML consumers (certain CI systems, strict schema validators) disable or mishandle them. Introduce anchors only where the consuming parser is known to support them, and always re-validate after editing.
Comments: the practical reason teams convert at all
The feature request behind most JSON-to-YAML conversions is comments. JSON has none by specification; YAML supports full-line comments, which turns a config from an opaque blob into documented infrastructure. The conversion workflow that captures this value: convert mechanically, then immediately annotate — why each value exists, what range is safe, which fields the upstream system ignores. Teams that convert without annotating preserve the data but miss the point; a commented YAML config transfers understanding between colleagues in a way the original JSON never could.
Kubernetes-flavored conversion notes
Kubernetes manifests are YAML with conventions layered on: apiVersion and kind at the top, metadata labels that must stay strings, and resources values that accept both numbers and strings like 500m. Converting JSON exports (helm template output, API dumps) into editable YAML means watching three traps: numeric-looking labels must stay quoted strings, the multi-document separator (three hyphens) between objects, and resource quantities that a naive converter might parse as numbers and corrupt. After converting, running kubectl dry-run validation catches all three classes before apply.
Linting converted output before trusting it
Generated YAML deserves the same lint pass as handwritten configs: a YAML linter flags inconsistent indentation, tabs sneaking into the file, duplicate keys, and the bare scalars that change type (yes, on, version strings). The sequence worth standardizing: convert, lint, then round-trip parse back to JSON and compare against the source. Each stage catches a different failure class — the converter handles structure, the linter handles style and traps, the round-trip proves equivalence. Skipping stages is how 'it looked fine' becomes a pipeline incident.
Where YAML and JSON genuinely differ
YAML is a superset of JSON in theory, which is why every valid JSON document has a YAML equivalent — but the conversion is still worth doing deliberately because the two formats encode edge cases differently. The famous one: no, yes, on, off parse as booleans in older YAML versions, so a JSON string "no" can arrive as false if it lands unquoted. Modern YAML 1.2 fixed most of these traps, but converters stay conservative and quote anything ambiguous — which is correct behavior even when it looks noisy.
Numeric fidelity is the second difference. JSON has one number type; YAML has integers, floats, sexagesimal, and infinity literals. A value like 12:30 in a converted document would be read as time notation in YAML 1.1, and very long digit strings (IDs, barcodes) can silently become scientific notation or lose precision if a downstream parser treats them as numbers. Quoting long numeric strings in the YAML output preserves them as the strings they were in JSON.
The practical upside of converting is readability and comments. YAML's indentation model makes config documents reviewable in a way dense JSON never is, and it permits comments — which JSON forbids — so a converted config can carry the reasoning next to the value. That is the honest criterion for choosing between the formats: machines exchange JSON, humans edit YAML, and the boundary should be drawn exactly there.
Common mistakes with this tool
- Leaving yes/on/version-style scalars unquoted and shipping type changes.
- Hand-retyping conversion and mixing tabs into indentation.
- Assuming round-trip equality means schema validity.
- Putting real secrets into pasted configs regardless of tooling.
Frequently asked questions
Is JSON a subset of YAML?
Yes — every valid JSON document is valid YAML, so conversion loses no data.
Why do some values get quoted?
To stop YAML from reinterpreting them — bare yes becomes boolean true; 1.10 becomes float 1.1.
What indentation does the output use?
Two spaces per level, spaces only — the convention YAML parsers expect.
Can I convert YAML back to JSON?
With a YAML-aware parser, yes — but comments and anchors do not survive the return.
Is it safe for production configs?
Conversion is local — but keep real secrets out of pasted configs entirely.
Why did my string "no" become a boolean?
YAML 1.1 treats no/yes/on/off as booleans. The fix is quoting: "no". Modern converters quote ambiguous strings automatically; if yours did not, add quotes.
Is YAML a safe replacement for JSON in APIs?
For interchange, no. JSON parsers are universal and predictable; YAML's flexibility creates parsing differences between implementations. Use JSON on the wire, YAML for human-edited config.