JSON to YAML converter
Paste or open a JSON file and the YAML shows up on the right. Copy it, or download it as a .yaml file. Nothing leaves your browser.
JSON
YAML
What is YAML?
YAML is a data format used mostly for config files. Docker Compose, Kubernetes, GitHub Actions, and Ansible all use it. It holds the same kinds of values as JSON, but it drops the braces and most of the quotes and uses indentation for nesting. You can also write comments in it, which JSON doesn’t allow.
The name is short for “YAML Ain’t Markup Language,” and .yaml and .yml files are the same thing.
What the output looks like
This is a small service config in JSON, and the YAML you get from it.
{
"name": "checkout-api",
"version": "3.8",
"port": 8080,
"debug": false,
"database": {
"host": "db.internal",
"port": 5432
},
"allowedOrigins": [
"https://shop.example.com",
"https://admin.example.com"
]
}name: checkout-api
version: '3.8'
port: 8080
debug: false
database:
host: db.internal
port: 5432
allowedOrigins:
- https://shop.example.com
- https://admin.example.comNotice that version comes out as '3.8', in quotes. Without them, YAML would read 3.8 as a number instead of the string you had in the JSON. The converter quotes anything like that, including values that look like dates, true/false, or null. Older libraries such as PyYAML also read yes, no, on, and off as booleans, so those get quoted too.
Is JSON valid YAML?
Usually, yes. YAML 1.2 is a superset of JSON, so most YAML parsers will load a .json file as is. Converting makes sense when people are going to read and edit the file by hand, or when you want to add comments.
Doing it in code
# Python, with PyYAML (pip install pyyaml)
import json, yaml
with open("config.json") as f:
data = json.load(f)
print(yaml.safe_dump(data, sort_keys=False))
// JavaScript, with js-yaml (npm install js-yaml)
import yaml from "js-yaml";
const output = yaml.dump(JSON.parse(text));
# Command line, with yq
yq -p json -o yaml config.jsonPyYAML sorts keys alphabetically by default. Pass sort_keys=False to keep them in your order.
Files can be up to 2 MB. If the JSON won’t parse, the error shows you the line, or you can run it through the JSON validator first. Going the other way? Use YAML to JSON.