JSON and YAML both store data as plain text. You can write the same settings in either one. But you often see JSON in web APIs. And you see YAML in config files for tools like Kubernetes and GitHub Actions. Why?
This guide compares the two with simple examples. It also shows the YAML mistakes that people often make. Then you can pick the right format and feel sure about it.
Quick answer: Use JSON when programs send data to each other, such as in web APIs. It is strict and simple. Use YAML for config files that people edit by hand. It is easier to read and allows comments.
What is YAML?
YAML is a data format. It uses indentation (spaces at the start of a line) to show structure. The name is a joke: it stands for “YAML Ain’t Markup Language”.
YAML and JSON can hold the same kinds of data. These are objects, lists, text, numbers, booleans (true or false) and null. In fact, YAML 1.2 was made so that almost any JSON file is also valid YAML. Want to learn more about JSON first? Read What is JSON?
JSON vs YAML: a side-by-side example
Here are some app settings in JSON:
{
"name": "my-app",
"version": "1.10",
"port": 8080,
"debug": false,
"features": ["login", "search"],
"database": {
"host": "localhost",
"user": "admin"
}
}And here are the same settings in YAML:
# Settings for my app
name: my-app
version: "1.10"
port: 8080
debug: false
features:
- login
- search
database:
host: localhost
user: adminThe main differences:
- JSON uses curly braces and square brackets. YAML uses indentation instead.
- JSON needs double quotes around every key and string. In YAML, you usually don’t need quotes.
- YAML writes each list item on its own line. Each item starts with a dash.
- YAML allows comments that start with
#. JSON does not.
Comments: YAML has them, JSON doesn’t
Comments are notes for people. Programs ignore them. They are very useful in config files. There, you can explain why a setting has a certain value. YAML allows comments. Standard JSON does not.
Some tools use a format in between, called JSONC. It means “JSON with Comments”. Files like tsconfig.json and VS Code settings are JSONC.
Do you need strict JSON from one of these files? The JSONC to JSON converter removes the comments and the extra commas at the end for you. You can read more in JSON comments.
Indentation: YAML’s biggest strength and weakness
In YAML, the spaces at the start of a line decide where a value belongs. This keeps files clean. But small mistakes can change the meaning. Look at this:
database:
host: localhost
user: adminHere user is not indented, so it is no longer part of database. The file is still valid, so you see no error. Your app just reads the wrong setting.
Two more rules to remember:
- YAML does not allow tabs for indentation. Use spaces only.
- Each level must use the same indentation. Most people use two spaces.
JSON does not care about spaces at all. You can write a whole JSON file on one line. It still means the same thing.
YAML traps to watch out for
YAML does not need quotes. So it has to guess the type of each value. Sometimes it guesses wrong.
yes, no, on and off
Older YAML rules (version 1.1) treat yes, no, on and off as booleans. So a country code can turn into false:
country: NO # may be read as false
country: "NO" # always the text NOYAML 1.2 fixed this. Now only true and false are booleans. But some popular libraries, such as PyYAML for Python, still follow the 1.1 rules. Putting quotes around the value is always safe.
Numbers that start with zero
In YAML 1.1, a number that starts with 0 can be read as an octal number (base 8). For example, 0755 becomes 493. A ZIP code like 01234 can lose its first zero or change value. Put quotes around codes and IDs.
Version numbers and decimals
YAML reads version: 1.10 as the number 1.1, so the last zero is lost. Write version: "1.10" to keep it as text.
Values that look like dates or null
A parser is the part of a program that reads the file. Some parsers turn 2026-11-23 into a date. Some turn ~ or null into an empty value. Put quotes around them if you want plain text.
You don’t have to remember all of this when you convert. The JSON to YAML converter adds quotes for you around strings like yes, no, on, null and 08. So the YAML means exactly what your JSON meant.
Where each format is common
JSON is common for
- Web APIs and data sent between programs.
- Project files such as
package.json. - Data stored in browsers, logs and many databases.
YAML is common for
- Kubernetes manifests (the files that say what to run in a cluster).
- Docker Compose files.
- GitHub Actions workflows, stored in
.github/workflows. - Ansible playbooks and many other build and deploy tools.
- OpenAPI specs, which can be written in either YAML or JSON.
Which one should you use?
- Choose JSON when one program writes the data and another program reads it. It is strict, so there are fewer surprises.
- Choose YAML when people edit the file by hand and need comments. A config file is a good example.
- Follow your tools. If Kubernetes, Docker Compose or GitHub Actions expect YAML, use YAML. If an API expects JSON, send JSON.
How to convert between JSON and YAML
To change JSON into YAML, paste your JSON into the JSON to YAML converter. Pick a 2- or 4-space indent. Then copy or download the YAML.
To go the other way, use the YAML to JSON converter. It follows YAML 1.2 rules, so yes and no stay text. It also expands anchors and aliases. These are YAML’s way to reuse a block.
The converter shows errors with their line and column. A file with several documents split by --- becomes a JSON array. Comments are lost, because JSON can’t store them.
Common questions
Is YAML a superset of JSON?
Mostly, yes. A superset means YAML includes everything JSON has, and more. YAML 1.2 was made so that valid JSON is also valid YAML. The opposite is not true, because YAML has comments and other features JSON does not have.
Is YAML better than JSON?
Neither is better for everything. YAML is easier for people to read and edit. JSON is stricter and simpler for programs.
Can I use tabs in YAML?
No. YAML does not allow tabs for indentation. Use spaces, usually two for each level.
Why does my YAML value turn into true or false?
Your parser probably follows the older YAML 1.1 rules. There, yes, no, on and off are booleans. Put the value in quotes to keep it as text.