How to convert YAML to JSON
Converting YAML to JSON here takes three steps, and nothing leaves your browser.
- Paste or open. Paste YAML into the converter, use Open file for a .yaml or .yml file, or drop the file onto the YAML pane.
- Pick an indent. Choose 2 spaces, 4 spaces, tab, or minified. The JSON updates as you type.
- Take it with you. Copy the JSON, download it as a .json file, or make a share link.
If a line isn't valid YAML, the converter tells you the line and column, explains the problem in plain English, and keeps your last valid JSON on screen while you fix it.
What this converter handles
Real config files use more than plain keys and values. Here's what happens to the parts JSON doesn't have a direct match for.
- Anchors and aliases
&defaults *defaults - Expanded into full copies, since JSON has no way to reference another value.
- Merge keys
<<: *defaults - Merged into the map. Keys you set yourself win over merged ones.
- Multiple documents
--- - Returned as a JSON array with one item per document, plus a notice so it is never a surprise.
- Dates
released: 2026-09-24 - Written as ISO 8601 strings.
- yes, no, on, off
enabled: yes - Kept as strings, following YAML 1.2. Only true and false become booleans.
- Infinity and NaN
.inf -.inf .nan - JSON can’t store these, so they become null, and a warning names the key.
- Very large integers
id: 9007199254740993 - Numbers above 2^53 get a warning, because JavaScript can’t hold them exactly.
- Comments
# like this - Left out, since JSON has no comment syntax. A one-time note tells you.
YAML vs JSON: key differences
YAML is built for people editing config by hand. JSON is built for programs passing data around. Most of the differences follow from that.
| Feature | YAML | JSON |
|---|---|---|
| Comments | # supported | Not supported |
| Reusing values | &anchor and *alias | Not supported |
| Quoting strings | Usually optional | Always double quotes |
| Several documents | Yes, split by --- | One value per file |
| Structure | Indentation | Braces and brackets |
| Typical use | Config: CI, Kubernetes, Compose | APIs and data exchange |
Converting in this direction drops YAML-only features: comments disappear, and anchors are written out as
full copies. The few values JSON can't store exactly, like .inf, are listed in the section above.
Convert YAML to JSON in Python
Install PyYAML with pip install pyyaml, then read with safe_load and write with
json.dumps. Use safe_load, not load: it only builds plain dicts, lists,
strings and numbers, so a file you didn't write can't create arbitrary Python objects.
import json import yaml with open("config.yaml") as f: data = yaml.safe_load(f) print(json.dumps(data, indent=2, default=str))
default=str turns YAML dates into strings, because json.dumps can't write Python date
objects.
Tested with Python 3.11.3 and PyYAML 6.0.1
Convert YAML to JSON on the command line
Three ways to do it in a terminal, depending on what's already installed. Each one reads
config.yaml and prints JSON, so redirect it with > to save a file.
yq -o=json config.yaml > config.json python3 -c 'import sys, json, yaml; print(json.dumps(yaml.safe_load(sys.stdin), indent=2, default=str))' < config.yaml npx js-yaml config.yaml > config.json mikefarah/yq · tested with yq 4.53.6
Tested with Python 3.11.3 and PyYAML 6.0.1
Tested with Node 22.18.0 and js-yaml 4.3.2
yq from mikefarah is a single binary that also handles JSON, XML and TOML. The Node.js command runs the
js-yaml package's own command-line tool through npx, so there is nothing to install
globally. It writes dates as full timestamps, like 2026-09-24T00:00:00.000Z.
Is my data private?
Yes. The converter is JavaScript running in this tab. Your YAML is parsed in memory and is never sent anywhere,
and an automated test checks that on every build. Share links keep the YAML after the # in the
address, a part browsers never send to a server.
The only thing the site counts is anonymous page visits, through Cloudflare Web Analytics, which uses no cookies. Your theme and indent choice are saved in your own browser. Your YAML never is.
Frequently asked questions
How do I convert YAML to JSON?
Paste your YAML into the left pane or open a .yaml file. The JSON appears on the right as you type. Pick an indent, then copy the result or download it as a .json file. It all runs in your browser, so there is nothing to install and no sign-up.
How do I convert YAML to JSON in Python?
Install PyYAML (pip install pyyaml), load the file with yaml.safe_load, and write it with json.dumps(data, indent=2, default=str). The default=str part handles dates, which JSON can’t store natively. The full snippet, tested with the versions listed, is in the Python section above.
Is my YAML uploaded anywhere?
No. Conversion runs in your browser tab, and the page never sends your YAML in any request. Share links keep the YAML after the # in the URL, which browsers don’t send to servers. An automated test checks this on every build of the site.
What happens to comments when I convert YAML to JSON?
They’re left out. JSON has no comment syntax, so there is nowhere to put them. If your YAML had comments, the tool shows a short note so you know they aren’t in the output. If you need to keep a note, store it in a regular field such as description instead.
How are multiple YAML documents (---) converted?
Each document becomes one item in a JSON array, in the same order. A notice tells you how many documents were found, so a single object turning into an array is never a surprise. Documents that hold only comments are skipped.
Why do yes and no stay as text instead of true and false?
This tool follows YAML 1.2, where only true and false are booleans. In YAML 1.1, yes, no, on and off were booleans too, which famously turned the country code NO (Norway) into false. Quote a value if you want to be explicit.
What’s the difference between .yml and .yaml?
Only the name. Both extensions hold the same YAML format. The YAML project recommends .yaml, while .yml is common in tools like Docker Compose. Renaming a file from one to the other changes nothing about its contents, so use whichever your tools already expect. This converter opens both.
Is YAML a superset of JSON?
Almost. YAML 1.2 was designed so nearly all valid JSON is also valid YAML, so a YAML parser usually reads JSON fine. There are rare edge cases, such as duplicate keys, which many JSON parsers accept but YAML forbids, and keys longer than 1,024 characters.