JSON to YAML Converter
Convert JSON to YAML and YAML back to JSON with a YAML 1.2 parser that expands anchors and rejects duplicate keys. Runs locally in your browser.
The interactive tool loads here when JavaScript runs.
About this toolWhat is the JSON to YAML Converter?
The JSON to YAML Converter converts JSON into YAML and YAML back into JSON. It is handy when a tool wants its configuration in YAML but your data came out of an API, or when you need to paste a YAML snippet into code that expects JSON.
Both directions use the yaml library with YAML 1.2 rules. Nested mappings, arrays, anchors and aliases, and multi-line block strings are supported. Duplicate keys, cyclic aliases and values JSON cannot represent (such as .inf) are rejected instead of silently losing data.
Comments in YAML do not survive the trip to JSON, because JSON has no comment syntax. A file with several YAML documents separated by --- needs to be converted one document at a time.
- JSON to YAML and YAML to JSON
- YAML 1.2 parsing for nested mappings, lists, anchors and multiline strings
- Rejects duplicate keys, cyclic aliases and non-finite numbers
- One-click copy
- Runs locally in your browser
Updated
How to use the JSON to YAML Converter
- Paste JSON or YAML into the input box.
- Click JSON → YAML or YAML → JSON.
- Review the output, paying attention to values that should stay strings.
- Copy the result.
Worked examples
JSON config to YAML
Input
{"name":"api","replicas":3,"ports":[80,443],"version":"1.10"}Output
name: api replicas: 3 ports: - 80 - 443 version: "1.10"
The string "1.10" is quoted in the YAML so it is not read back as the number 1.1. Numbers stay unquoted.
YAML scalars that change type
Input
country: NO version: 1.10 on: true
Output
{"country": "NO", "version": 1.1, "on": true}Under YAML 1.2 rules NO stays a string, but 1.10 still becomes a float and loses its trailing zero. Quote version numbers in YAML.
Background and insight
YAML began in 2001, created by Clark Evans, Ingy döt Net and Oren Ben-Kiki. Its name originally meant "Yet Another Markup Language" and was later changed to the recursive "YAML Ain't Markup Language" to stress that it is for data, not documents. YAML 1.2, released in 2009, aligned YAML with JSON so that practically any JSON document is also valid YAML.
YAML's readability comes from indentation and minimal punctuation, and so do its traps. In YAML 1.1, unquoted no, yes, on and off are booleans, which is why a list of country codes containing NO (Norway) famously turned into false. Version strings like 1.10 are read as the number 1.1 in every YAML version. Tabs are not allowed for indentation. Quoting values that look like booleans or numbers avoids most of this.
JSON has the opposite trade-off: noisier to read, but nearly impossible to misinterpret. That is why many teams author configuration in YAML for humans and convert it to JSON for machines.
Common use cases
Writing Kubernetes and CI config
Turn a JSON object into YAML to paste into a manifest, docker-compose file or workflow.
Reading YAML in code
Convert a nested YAML settings block to JSON to use as a test fixture or API payload.
Comparing formats
See the same data side by side as JSON and YAML when choosing a config format.
Checking what YAML really means
Convert a suspicious YAML file to JSON to see exactly which values became numbers, booleans or null.
Tips and limitations
- The YAML output follows YAML 1.2, so a JSON string "NO" is written unquoted. Tools that still parse YAML 1.1 (PyYAML by default) will read that as false; add quotes by hand for those.
- Anchors (&base) and aliases (*base) are expanded in the JSON output, so the JSON can be much larger than the YAML it came from.
- An empty value (key:) becomes null in JSON, not an empty string.
- Indent with spaces only. A tab in YAML indentation is a parse error, and the message will point at that line.
- Run the YAML through the YAML Formatter first if you want consistent indentation before converting.
Sources and further reading
- YAML Ain't Markup Language (YAML) revision 1.2.2, YAML Language Development Team. The current YAML specification, aligned with JSON
- Boolean Language-Independent Type for YAML Version 1.1, YAML Language Development Team. The YAML 1.1 list of yes, no, on and off booleans
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format, IETF
- ECMA-404: The JSON data interchange syntax, Ecma International
Frequently asked questions
Is every JSON file valid YAML?
Practically, yes. YAML 1.2 was revised so that JSON documents parse as YAML, which is why a YAML 1.2 parser can read most JSON directly. A few edge cases differ, such as very long keys or unusual escape sequences, but ordinary JSON configuration converts cleanly.
Does YAML to JSON support anchors and multi-line strings?
Yes. Nested mappings, lists, anchors and aliases, and block strings using | or > are handled by a YAML 1.2 parser. Aliases are expanded in the JSON. Comments do not carry over because JSON cannot represent them, and multiple documents separated by --- must be converted separately.
Why did my YAML "no" turn into false?
In YAML 1.1, unquoted yes, no, on, off, y and n are booleans. This converter uses YAML 1.2, where only true and false are booleans, but many tools still use 1.1 rules. Quote the value ("no") so every parser keeps it as a string.
Can YAML have comments that survive conversion to JSON?
YAML supports # comments, but JSON has no comment syntax, so comments are dropped when converting YAML to JSON. If you need to keep notes, move them into a field such as "description", or keep the YAML file as the source of truth.
Why does the converter reject my YAML with duplicate keys?
A mapping that repeats a key is an error in the YAML specification, and silently keeping the last value is a common source of configuration bugs. The converter stops and reports it, so you can decide which value is correct instead of losing one without noticing.
Is there an in-depth guide to the JSON to YAML Converter?
Yes. “JSON vs YAML: Differences, Gotchas and When to Convert” covers the background, how it works, common pitfalls and worked examples. Read the full guide.
Related Tools You May Like
Free, in-browser tools that pair well with this one.