๐ JSON to YAML Converter
By Shihab Mia ยท Updated 2026-08-04
Paste valid JSON above, then choose Convert to YAML.
This JSON to YAML converter turns a block of JSON into clean, readable YAML right in your browser. Paste your JSON, choose an indent width, and you get properly indented YAML with nested objects as maps, arrays as dash lists, and strings quoted only when they actually need it. Nothing is uploaded, the conversion happens entirely on your device.
What is the JSON to YAML?
JSON (JavaScript Object Notation) and YAML (YAML Ain't Markup Language) describe the same shape of data: objects (maps of keys to values), arrays (ordered lists), and scalars (strings, numbers, booleans, null). They differ in syntax. JSON leans on braces, brackets, quotes, and commas, which makes it precise and easy for machines but noisy for humans. YAML drops most of that punctuation and uses indentation to show structure, which is why it has become the default for configuration files in tools like Docker Compose, Kubernetes, GitHub Actions, Ansible, and CircleCI.
Converting from JSON to YAML is mostly a matter of re-formatting. An object becomes a set of "key: value" lines, one per key, each indented under its parent. An array becomes a list of lines that each start with a dash and a space. A nested object or array simply moves to the next indentation level. Because YAML is a strict superset of JSON's data model, every valid JSON document has at least one valid YAML representation, so this direction of conversion never loses information. The reverse, YAML to JSON, can lose things, which is worth knowing if you plan to round-trip.
The one part that needs care is quoting. In YAML a bare string like London needs no quotes, but a value such as true, 42, or yes would be read back as a boolean or a number rather than text, and a value containing a colon followed by a space (like Yes: maybe) would be mistaken for a nested key. This converter applies those rules for you: it leaves plain strings unquoted for readability and wraps only the values that would otherwise be misread, using double quotes with correct escaping. The result is YAML that is both tidy and safe to round-trip back to the same data.
YAML also has features that plain JSON has no equivalent for, and understanding them helps explain why the conversion is one-directional in practice. YAML supports line comments starting with a hash sign, which JSON cannot express at all, so a converter has nothing to preserve there but you can add comments by hand after converting. YAML also supports anchors and aliases (written with an ampersand and an asterisk) that let a document reuse a value in multiple places without repeating it, and it supports multiple documents in a single file separated by three dashes. A straightforward JSON-to-YAML conversion, like the one this tool performs, does not introduce anchors or multi-document splits on its own, it produces a single, flat, easy-to-diff YAML document that matches your JSON structure one for one.
One quirk worth knowing before you hand-edit the output: older YAML parsers (YAML 1.1, still the default in many libraries) treat bare words like yes, no, on, off, and even the country code NO as booleans, a well-known trap nicknamed the Norway problem. This converter always writes JSON booleans as the literal words true and false and quotes any string value that could be misread, so the output stays safe across YAML parser versions.
When to use it
- Turning a JSON API response or config snippet into YAML for a Docker Compose, Kubernetes, or GitHub Actions file.
- Converting a settings object exported as JSON into the YAML format your tool or framework expects.
- Making a dense JSON payload easier to read and review by reformatting it as indented YAML.
- Migrating configuration from a JSON-based system to a YAML-based one without retyping it by hand.
- Preparing an Ansible playbook variables file or a Helm values.yaml from JSON produced by another script.
- Sharing a readable, comment-friendly version of an API schema or fixture with teammates who prefer YAML.
How to use the JSON to YAML
- Paste or type your JSON into the input box (the Load sample button fills in an example).
- Pick the indent width, 2 spaces is the common default for YAML, 4 spaces is also supported.
- Click Convert to YAML to generate the result below.
- Check the YAML output, then use Copy to put it on your clipboard. Invalid JSON shows a clear error message.
Formula & method
Worked examples
A flat JSON object with a string, a number, and a boolean.
- Input: {"name": "Ada", "age": 36, "admin": true}
- Each key becomes its own line at indent level 0.
- The string "Ada" is safe as a plain scalar, so it stays unquoted.
- The number 36 and boolean true are written bare.
Result: name: Ada age: 36 admin: true
A JSON object containing an array and a nested object.
- Input: {"skills": ["math", "code"], "address": {"city": "London"}}
- The skills key has no inline value, so its array moves to the next indent level.
- Each array element becomes a dash line: "- math" and "- code".
- The address object also moves one level deeper as "city: London".
Result: skills: - math - code address: city: London
A value that must be quoted to round-trip safely.
- Input: {"flag": "true", "label": "Yes: maybe"}
- The string "true" would be read back as a boolean, so it is quoted.
- The string "Yes: maybe" contains a colon and space, which would look like a nested key, so it is quoted.
- Both are emitted with double quotes and proper escaping.
Result: flag: "true" label: "Yes: maybe"
How JSON structures map to YAML
| JSON | YAML equivalent | Notes |
|---|---|---|
| { "a": 1 } | a: 1 | Object key becomes a key: value line |
| [1, 2, 3] | - 1\n- 2\n- 3 | Array element becomes a dash line |
| { "a": { "b": 1 } } | a:\n b: 1 | Nested object indents one level |
| { "a": [] } | a: [] | Empty array stays inline |
| { "a": {} } | a: {} | Empty object stays inline |
| null | null | Null is written as the word null |
When a string value gets quoted in YAML
| String value | Output | Reason |
|---|---|---|
| London | London | Plain text, safe unquoted |
| true | "true" | Would parse as a boolean |
| 42 | "42" | Would parse as a number |
| Yes: maybe | "Yes: maybe" | Colon and space looks like a key |
| (empty string) | "" | Empty value must be explicit |
Where converted YAML files are typically used
| File / tool | Common filename | Why YAML over JSON |
|---|---|---|
| Docker Compose | docker-compose.yml | Comments and shorter syntax for service definitions |
| Kubernetes manifests | deployment.yaml | Multi-document files, easier to diff in code review |
| GitHub Actions | .github/workflows/*.yml | Readable step lists without brace nesting |
| Ansible playbooks | playbook.yml | Task lists read almost like plain English |
| Helm charts | values.yaml | Human-edited defaults with inline comments |
Common mistakes to avoid
- Assuming numbers stored as strings stay strings. If your JSON has "port": "8080" (a string) the converter quotes it as "8080" so it stays text. If you wanted the number 8080, change the JSON to remove the quotes before converting.
- Pasting JSON with trailing commas or comments. Standard JSON does not allow trailing commas or comments. If your input has them, the parser reports an error. Remove the trailing comma or comment line and convert again.
- Mixing tabs and spaces in the original data. YAML forbids tabs for indentation, but that only matters when writing YAML by hand. This tool always indents with spaces, so the output is safe, just keep using its result rather than re-indenting with tabs.
- Expecting key order to be sorted. The converter preserves the key order of your JSON object exactly as written. It does not alphabetize keys, so if you need sorted output, sort the JSON first.
- Typing bare yes, no, on, or off after hand-editing the output. This converter always writes JSON booleans as true or false and quotes ambiguous strings, so its output is safe. But if you later hand-edit the YAML and type a bare yes or off, older YAML 1.1 parsers can silently read it as a boolean instead of text, the well-known "Norway problem". Quote it yourself if you mean the literal word.
- Expecting anchors, aliases, or comments to appear automatically. JSON has no concept of comments, anchors, or aliases, so there is nothing for the converter to reuse. It always outputs a single flat document with values written out in full. You can add comments or introduce anchors by hand afterward if your workflow needs them.
Glossary
- JSON
- JavaScript Object Notation, a text format for data built from objects, arrays, strings, numbers, booleans, and null.
- YAML
- YAML Ain't Markup Language, a human-friendly data format that uses indentation instead of braces and brackets.
- Map
- A collection of key-value pairs, called an object in JSON and a mapping in YAML.
- Sequence
- An ordered list of values, called an array in JSON and written with dash lines in YAML.
- Scalar
- A single value that is not a container: a string, number, boolean, or null.
- Plain scalar
- A YAML string written without quotes, allowed only when it cannot be misread as another type or as syntax.
- Anchor and alias
- A YAML feature (marked with & and *) that lets one value be defined once and reused elsewhere in the same document. JSON has no equivalent.
- Flow style
- YAML written with JSON-like brackets and braces on one line, as opposed to block style, which uses indentation across multiple lines.
Frequently asked questions
How do I convert JSON to YAML?
Paste your JSON into the input box, choose an indent width (2 or 4 spaces), and click Convert to YAML. The tool parses the JSON and serializes it as indented YAML, which you can then copy. Everything runs in your browser, so your data is never uploaded.
Is my data sent to a server?
No. The conversion is 100% client-side vanilla JavaScript running in your browser. Your JSON never leaves your device, which makes the tool safe to use even with private or sensitive configuration.
What is the actual difference between JSON and YAML?
They represent the same data model (objects, arrays, and scalars) but with different syntax. JSON uses braces, brackets, and quotes and is strict and machine-friendly. YAML uses indentation and mostly unquoted text, plus extras JSON lacks entirely, like comments, anchors and aliases for reuse, and multiple documents separated by three dashes in one file.
Why are some of my strings wrapped in quotes?
A string is quoted only when leaving it bare would change its meaning. Values like true, 42, or null would be read back as a boolean, number, or null, and strings with a colon and space could be mistaken for a nested key. Quoting these keeps the YAML round-tripping to the same data.
What happens if my JSON is invalid?
The tool uses a strict JSON parser. If your input has a syntax error, such as a trailing comma, a missing quote, or a stray comment, it shows a clear error message instead of producing output. Fix the highlighted issue and convert again.
Does the converter keep my key order?
Yes. The output follows the exact order of keys in your JSON object. It does not sort or rearrange keys, so the YAML mirrors the structure you pasted in.
Can I convert YAML back to JSON?
Yes, use the companion YAML to JSON converter for the reverse direction. Because a plain JSON-to-YAML output uses only the common subset of maps, sequences, and scalars, it converts back cleanly. YAML files that add comments, anchors, or multiple documents will lose those extras when converted to JSON, since JSON has no way to express them.
Does the output include YAML comments?
No, and it never can automatically. JSON has no comment syntax, so there is nothing in your input for the converter to carry over. If you want comments in the final file, add them by hand with a hash sign after converting.
Should I use 2-space or 4-space indentation?
Either is valid YAML. Two spaces is the de facto standard used by Kubernetes, Docker Compose, and most style guides, so it is the safer default if a specific tool does not dictate otherwise. Four spaces reads a little more openly for deeply nested structures; pick 4 if your team already uses it consistently.
Does it matter if I save the file as .yml or .yaml?
No, both extensions are treated identically by every standard YAML parser. .yml is more common because of old 3-character filename habits, and .yaml is the extension the YAML specification itself recommends. Use whichever convention your project or tool already expects.
Can this converter handle arrays of objects, like a list of API records?
Yes. Each object in the array becomes its own block under a dash, with the object's keys indented beneath it. This is the most common shape for things like a list of users or log entries, and it converts the same way as any other nested structure.