Overview
Introduction
YAML has become the default format for Kubernetes manifests, CI pipelines, and countless config files, but many tools still emit JSON. This converter turns that JSON into clean, properly quoted block-style YAML you can drop straight into a config file.
It exists because that gap shows up constantly in DevOps workflows. `kubectl get pod x -o json` gives you JSON, but the manifest you're actually going to commit is YAML. Converting by hand means remembering YAML's quoting rules for reserved words and special leading characters, which is exactly the kind of detail that's easy to get subtly wrong under time pressure.
What Is JSON to YAML Converter?
A JSON-to-YAML converter re-serializes a JSON value using YAML's block style: two-space indentation, dash-prefixed list items, and colon-separated key-value pairs, quoting only the scalars that would otherwise be ambiguous.
YAML is a strict superset of JSON in terms of what it can represent, but idiomatic YAML avoids JSON's flow-style braces and brackets in favor of indentation-based block style, since that's what makes hand-edited YAML readable. This tool targets that idiomatic block style instead of simply re-indenting flow-style output, so the result looks like YAML a person would actually write.
How JSON to YAML Converter Works
The tool parses your JSON, then walks the resulting structure recursively, emitting nested objects as indented key blocks and arrays as dash-prefixed lists. Strings stay unquoted unless they collide with a YAML reserved word (true, false, null, ~), start with a character that has special meaning (-, ?, :, #, etc.), or could be misread as a number.
That selective quoting matters because YAML's type inference is based on a string's literal form. An unquoted `yes` or `on` is parsed as a boolean under YAML 1.1, and an unquoted `3.0` is parsed as a number, not a string. The converter checks each scalar against those rules before deciding whether to wrap it in quotes, so a JSON string value round-trips back to a string when the YAML is parsed instead of silently changing type.
When To Use JSON to YAML Converter
Use it when a tool gives you JSON but the file you need to write is YAML, for example converting a JSON API response into a Kubernetes ConfigMap, a GitHub Actions step, or a docker-compose fragment.
It's also useful for producing readable YAML documentation from a JSON example. Block-style YAML with clean quoting is generally easier for a person to scan than the equivalent JSON, even outside of any specific tool that requires YAML as input.
Often used alongside JSON to XML Converter, JSON to CSV Converter and JSON Formatter & Beautifier.
Features
Advantages
- Produces clean, human-readable block-style YAML rather than YAML's less common flow style.
- Automatically quotes only the strings that actually need it, keeping output tidy.
- Handles arbitrarily nested objects and arrays.
- No server round-trip, which matters for config files that may contain secrets or internal hostnames.
Limitations
- Does not generate YAML anchors, aliases, or multi-document separators.
- Comments are not preserved or generated, since JSON has no comment concept to carry over.
- Very large numbers or numbers with trailing zeros may render slightly differently than the original source formatting, since JSON itself doesn't preserve numeric formatting.
YAML vs. JSON: When to Use Each
| YAML | JSON | |
|---|---|---|
| Required by | Kubernetes, GitHub Actions, most CI configs | REST APIs, JavaScript data |
| Supports comments | Yes | No |
| Whitespace-sensitive syntax | Yes, indentation defines structure | No, braces and brackets define structure |
| Best for | Hand-edited config and manifest files | Programmatic data exchange |
Examples
Best Practices & Notes
Best Practices
- Review quoted strings after conversion: if a value looks like it shouldn't be quoted, check whether it collides with a YAML reserved word.
- For Kubernetes manifests, diff the converted YAML against a known-good example to confirm key ordering and structure match expectations.
- Keep a JSON source of truth and regenerate YAML at build time rather than hand-editing generated YAML.
- If the converted YAML feeds a tool you don't control the parser version of, treat the YAML 1.1 reserved-word quoting as a feature, not noise: it protects against older loaders that still read yes/no/on/off as booleans.
- For a top-level JSON array, expect a bare dash-prefixed sequence with no wrapping key. Add an enclosing object in the JSON first if your target file needs a named top-level key.
- When converting config that will be committed to version control, run the output through a YAML linter once, since this tool guarantees syntactic correctness but not conformance to a specific team's style rules (indent width, quote style, key casing).
Developer Notes
The quoting logic checks a value against several independent rules before deciding whether it needs quotes: YAML 1.1 reserved words (true/false/null/yes/no/on/off and their case variants, plus ~), a leading character with special meaning in YAML syntax (-, ?, :, ,, brackets, braces, #, &, *, !, |, >, quote characters, %, @, or a backtick), leading or trailing whitespace, an embedded colon or hash (which could be misread as a key separator or a comment), and strings that look like a decimal, hex, or octal number. Any string matching one of those gets quoted using JSON.stringify, which both wraps it in double quotes and guarantees any special characters inside it (backslashes, embedded quotes) are escaped validly, instead of hand-rolling YAML's own quoting escape rules. Object keys go through the identical check, so a key like "yes" or one containing a colon gets quoted exactly the same way a value would be. Arrays and objects nested inside array items are handled by re-indenting the nested block and merging its first line onto the dash, which is why an object as an array item renders as "- key: value" with subsequent keys aligned underneath, rather than the dash sitting on its own line above the block.
JSON to YAML Converter Use Cases
- Converting a JSON API response into a Kubernetes manifest fragment
- Turning JSON config into a GitHub Actions or GitLab CI YAML step
- Migrating a JSON-based settings file to a YAML-based tool
- Producing readable YAML documentation from a JSON example
- Converting the JSON output of a CLI tool (kubectl, aws, gcloud) into YAML for a manifest or IaC template
- Spot-checking how a specific JSON value would be quoted in YAML before writing it by hand into an existing manifest
Common Mistakes
- Assuming the output includes YAML anchors or references. It always produces flat, expanded structures.
- Not noticing when a string like "yes" or "on" gets quoted. That's intentional, since unquoted it would be read as a boolean in YAML.
- Pasting JSON with comments (JSONC), which fails to parse since it isn't valid JSON.
- Assuming a top-level JSON array converts under a synthetic key; it renders as a bare sequence with no wrapping key at all.
- Expecting the converted YAML to carry over comments from wherever the JSON originally came from. JSON has no comment syntax, so there's nothing for the converter to preserve.
Tips
- If your target tool expects a specific key order, check the converted YAML. Key order always follows the source JSON's insertion order, with one caveat: integer-like keys ("0", "1") are always ordered first, ahead of any string keys, following standard JavaScript object key iteration.
- For deeply nested configs, format the JSON first so it's easier to sanity-check before converting.
- If you're not sure whether a value will need quoting, convert it on its own first (as a single-key object) to check, rather than scanning a large converted document for one quoted string.
- Empty objects and arrays render as compact {} and [] rather than an indented block. That's expected and matches how most hand-written YAML represents "nothing here".