JSON → YAML
JSON to YAML Converter
JSON to YAML conversion transforms a JSON document into human-readable block-style YAML. JSON objects become YAML mappings, arrays become block sequences, and all scalar types map directly. This tool uses js-yaml v5 with YAML 1.2, outputting only true/false as booleans. The result is clean, indentation-based YAML ready for use in Kubernetes, Helm, GitHub Actions, and Ansible. All conversion runs client-side with no data sent to any server.
How JSON to YAML Conversion Works
Last updated: November 2026
JSON (JavaScript Object Notation) is a lightweight data format used for APIs and configuration. YAML (YAML Ain't Markup Language) is a human-readable superset that adds comments, multi-line strings, and anchors. This converter parses your JSON using the browser's built-in JSON.parse(), then serializes the result to block-style YAML using js-yaml v5 with your chosen indentation.
Paste your JSON into the left panel and click Convert to YAML — or just paste and the conversion runs automatically. The YAML output appears in the right panel and can be copied or downloaded.
JSON → YAML Type Mapping
Every JSON type maps cleanly to a YAML equivalent. The output is always valid YAML 1.2.
| JSON type | YAML output | Notes |
|---|---|---|
| Object {} | Block mapping | key: value with indentation |
| Array [] | Block sequence | - item per line |
| "string" | Bare scalar | Quoted when it contains special chars |
| 42 / 3.14 | 42 / 3.14 | Scientific notation is expanded |
| true / false | true / false | Compatible with YAML 1.1 and 1.2 |
| null | null | Compatible with YAML 1.1 and 1.2 |
Tips & Tricks
Add comments after converting
JSON can't carry comments, but YAML can. Once converted, open the output in the YAML Formatter and add # comments to document non-obvious keys before saving to your repo.
Scientific notation expands
1e6 in JSON becomes 1000000 in YAML after JSON.parse. Correct data — just a different representation than you might expect.
Keys with colons get quoted
A JSON key like "key: subkey" becomes 'key: subkey' (single-quoted) in YAML to avoid mapping syntax ambiguity. Handled automatically.
Empty arrays stay as []
An empty JSON array [] remains [] in YAML block output — there are no items to place on indented lines.
Long strings won't wrap
This tool uses lineWidth: -1 in js-yaml, disabling automatic wrapping. Use the YAML Formatter and apply the | literal block style manually if needed.
Unicode escapes become real characters
A in JSON becomes A in YAML because JSON.parse decodes Unicode escapes before conversion. No data loss.
Code Examples
Node.js
import yaml from 'js-yaml';
import fs from 'fs';
const json = fs.readFileSync('data.json', 'utf8');
const data = JSON.parse(json);
const yamlString = yaml.dump(data, { indent: 2, lineWidth: -1 });
fs.writeFileSync('data.yaml', yamlString); Python
import json
from ruamel.yaml import YAML
with open('data.json') as f:
data = json.load(f)
yaml = YAML()
yaml.default_flow_style = False
with open('data.yaml', 'w') as f:
yaml.dump(data, f)
# PyYAML also works (produces YAML 1.1):
# import yaml
# yaml.dump(data, open('data.yaml', 'w'), default_flow_style=False) CLI
# Using yq (https://github.com/mikefarah/yq)
yq -p=json -o=yaml data.json > data.yaml
# Using Python one-liner
python3 -c "import json,yaml,sys; print(yaml.dump(json.load(sys.stdin), default_flow_style=False))" < data.json
# Using Node.js + js-yaml
node -e "const y=require('js-yaml'),fs=require('fs'); process.stdout.write(y.dump(JSON.parse(fs.readFileSync(process.argv[1],'utf8')),{lineWidth:-1}))" data.json Frequently Asked Questions
- What is JSON to YAML conversion?
- JSON to YAML conversion transforms a JSON document into an equivalent YAML representation. JSON objects become YAML block mappings, arrays become block sequences, and all scalar types map directly. The resulting YAML is human-readable, uses indentation instead of brackets, and omits quotes on most string values. The conversion is performed by js-yaml v5's
yaml.dump()function, which accepts the parsed JavaScript object fromJSON.parse()and serializes it to block-style YAML. No data is lost: every string, number, boolean, null, nested object, and array is represented in the output. The main benefit of converting JSON to YAML is to produce a format that accepts comments and is easier to read and edit by hand — particularly for configuration files in tools like Kubernetes, Docker Compose, GitHub Actions, Helm, and Ansible that all use YAML as their primary format. - Why would I convert JSON to YAML?
- YAML is easier to read and edit by hand — no trailing comma rules, no mandatory quotes on keys, and support for inline and block comments. It is the standard format for Kubernetes manifests, Docker Compose files, GitHub Actions workflows, Helm chart values, and Ansible playbooks. Converting a JSON config to YAML lets you use it in those ecosystems and add inline comments to document non-obvious keys. YAML is also significantly more concise for deeply nested structures because it uses indentation instead of brackets, curly braces, and commas. A common workflow is to retrieve configuration or schema data from a JSON API, convert to YAML, and then check it into a Git repository as a human-editable configuration file. The reverse workflow — converting YAML back to JSON — is covered by the YAML to JSON converter on this site.
- What JSON features survive YAML conversion?
- All data survives: objects, arrays, strings, numbers, booleans (true/false), and null. String values containing YAML special characters — colons followed by a space, hash signs used as comments, leading dashes that would be parsed as list items, and others — are automatically quoted by js-yaml to avoid parsing ambiguity. For example, a JSON value like
"error: not found"becomes'error: not found'in YAML because the colon-space sequence would otherwise be interpreted as a mapping separator. Strings that look like YAML reserved words (true,null,yes) are also quoted to prevent type coercion by YAML parsers that may read the output file. No manual pre-processing of the JSON is required before conversion. - How are JSON booleans represented in YAML?
- JSON
trueandfalsebecome bare YAMLtrueandfalse— no quotes. This is compatible with both YAML 1.1 parsers (PyYAML, Docker Compose go-yaml v2, GitHub Actions, Ansible) and YAML 1.2 parsers (js-yaml v5, go-yaml v3, ruamel.yaml). Note that this converter does not output the YAML 1.1 boolean synonymsyes/no/on/off— it always usestrue/false, which is the safer choice because it is unambiguous in both YAML versions. If you needyes/noin the output for compatibility with a specific system, do a find-and-replace after conversion, though this is rarely necessary in modern tools. - How are JSON null values represented in YAML?
- JSON
nullbecomes barenullin YAML — compatible with YAML 1.1 and YAML 1.2 parsers including PyYAML, js-yaml, go-yaml v2 and v3, and ruamel.yaml. YAML also accepts~as a synonym for null, but js-yaml'sdump()function outputs the wordnullrather than the tilde for clarity. When reading the generated YAML back with any compliant parser,nullwill round-trip correctly to a null value. Note that JSON object keys cannot be null (the JSON specification requires string keys), so null only appears as a value, never as a key name. YAML allows arbitrary scalars as keys, but this converter only produces keys that originated from valid JSON string keys. - How are JSON numbers converted to YAML?
- Integers and floats become bare YAML scalars with no quotes. Scientific notation like
1e10is expanded to10000000000by JSON.parse before the YAML conversion, so the YAML output always contains the full decimal form. Very large integers aboveNumber.MAX_SAFE_INTEGER(9007199254740991) lose precision in JSON.parse because JavaScript uses IEEE 754 double-precision floating point — this affects 64-bit IDs common in distributed systems like Twitter Snowflake IDs. If your JSON contains large integer IDs, they should be stored as quoted strings in JSON to preserve precision. Floating-point numbers like0.1that cannot be represented exactly in IEEE 754 may appear with extra decimal digits in the YAML output due to floating-point representation — this is a characteristic of the number itself, not of the conversion process. - Does the YAML output use block or flow style?
- This tool produces block-style YAML, where objects use indented
key: valuepairs on separate lines and arrays use- itemlines. Block style is the most readable form and the standard for Kubernetes, Helm, and GitHub Actions configuration. Empty arrays[]and empty objects{}remain in inline flow style because there is no content to place on indented lines. YAML also supports inline flow style for non-empty structures (e.g.{key: value}), which is what JSON looks like — but js-yaml'sdump()produces block style by default. If you specifically need flow-style YAML output, pass theflowLevel: 0option in a custom js-yaml call, though this is unusual and rarely required in practice. - How are JSON strings with special characters handled?
- js-yaml automatically quotes strings that contain YAML-significant characters: colons followed by a space (which would be parsed as a mapping separator), hash signs (comment markers), leading dashes (list item indicators), leading and trailing whitespace, and strings that look like YAML reserved values (
true,false,null,yes,no). Single quotes are used when the string does not contain a single quote itself; double quotes are used when it does. This automatic quoting means you do not need to pre-process the JSON or worry about escaping — the output YAML will parse back to the same values without ambiguity. URLs containing colons (likehttps://example.com) are automatically single-quoted in the output. - Can I convert JSON to YAML in Python?
- Yes:
import json, yaml; data = json.load(f); yaml.dump(data, stream, default_flow_style=False). PyYAML'sdump()produces YAML 1.1 output — it will writetrue/falsefor booleans andnullfor null values, which is compatible with most parsers. Install viapip install PyYAML. For YAML 1.2 output with better handling of edge cases, use ruamel.yaml:from ruamel.yaml import YAML; y = YAML(); y.default_flow_style = False; y.dump(data, stream). Install ruamel.yaml viapip install ruamel.yaml. ruamel.yaml also preserves comment round-tripping if you later modify and re-serialize the YAML file, which PyYAML cannot do. - Can I convert JSON to YAML in Node.js?
- Yes:
import yaml from 'js-yaml'; const data = JSON.parse(jsonString); const yamlString = yaml.dump(data, { indent: 2, lineWidth: -1 }). Install vianpm install js-yaml. ThelineWidth: -1option disables js-yaml's automatic line-wrapping of long strings, which otherwise breaks long URLs or base64 values across multiple lines. Theindentoption controls the number of spaces per indentation level — 2 is standard for Kubernetes and most YAML formats. TypeScript typings are bundled with js-yaml v5, so no separate@types/js-yamlpackage is needed. This tool uses the same library with these exact options, so programmatic output will be identical to what you see in the browser converter. - Is my data sent to a server?
- No. The conversion runs entirely in your browser using js-yaml v5. Your data never leaves your machine and no account or sign-up is required. The js-yaml library is bundled as a static asset and loaded from the same origin as the page — no CDN calls or external requests are made during conversion. This makes the tool safe for sensitive JSON input such as API payloads containing private tokens, database credentials, or user data. The tool stores tab state in localStorage so your work persists between refreshes, but this data never leaves the browser. The tool also works fully offline after the initial page load because all JavaScript is cached by the browser.
- Can I add comments to the converted YAML?
- Not automatically — JSON has no comment syntax to map from, so there is nothing to translate. After conversion, open the output YAML in a text editor or in the YAML Formatter and add
#comments manually above or beside the keys you want to document. Comments are one of YAML's main advantages over JSON for configuration files. For example, in a Kubernetes manifest you might add# CPU request intentionally low for dev environmentabove a resource limit. Libraries like ruamel.yaml in Python can round-trip comments if you need programmatic comment manipulation, but js-yaml and PyYAML discard comments on parse.
Related Tools
Other free developer tools available on DevFormatter.
JSON Formatter
Format, validate, minify, and sort JSON. Detects duplicate keys and converts to YAML.
YAML Formatter
Format, validate, and convert YAML. Detects YAML 1.1 coercion risks and expands anchors.
YAML to JSON
Convert YAML to formatted JSON. Anchors expanded, runs in your browser.
XML to JSON
Convert XML to structured JSON with attributes preserved as @_ keys.