What Is YAML? Indentation Rules, Differences from JSON, and Common Mistakes
Updated: October 13, 2026 · AracMerkezi
YAML is a data format designed to be easy for humans to read. It is used in Docker Compose, Kubernetes, GitHub Actions, and many configuration files. It has fewer symbols than JSON; the structure is determined by indentation.
Basic syntax
name: Ayşe
age: 30
active: true
tags:
- php
- js
address:
city: Malatya
- Between a key and a value there is
:(a colon and a space). - List items start with
-. - Nested structure is indented with the same number of spaces.
- Comments start with
#.
Indentation rules
- Use only spaces; do not use tab characters. YAML does not accept tabs in indentation.
- Items at the same level must start with the same number of spaces; the common choice is 2 spaces.
- One level too much or too little indentation can change the meaning entirely or cause an error.
Differences from JSON
| Feature | YAML | JSON |
|---|---|---|
| Readability | High | Medium |
| Comments | Yes (#) | No |
| Structure | Indentation | Brackets |
| Multiline text | Supported | Only with \n |
| Trailing comma error | None | Yes |
YAML 1.2 is nearly a superset of JSON; that is, most valid JSON can also be read as YAML. In practice, however, tools implement different YAML versions.
Common mistakes
- Using tabs. Set your editor to insert spaces instead of tabs.
- Not leaving a space after the colon.
name:Ayşeis read as text, whilename: Ayşebecomes a key-value pair. - Specially meaningful values. In older YAML versions,
yes,no,on,offcan turn into booleans. The country codeNO(Norway) can accidentally becomefalse. Put such values in quotes:"NO". - Text containing a colon.
time: 10:30may be interpreted as a number by some parsers; write it with quotes. - Text that looks like a number. If the version number
1.10is converted to a number, it becomes1.1; write"1.10".
YAML ↔ JSON conversion
Using JSON to send a configuration to an API and YAML to edit it is a common approach. The YAML to JSON Converter converts common YAML structures (nested objects, lists, text, numbers, booleans) to JSON. For the reverse direction, there is the JSON to YAML Converter tool. To validate the result, you can use the JSON Formatter.
Converters do not cover every YAML feature. Advanced structures such as anchors and aliases (& and *), multi-document files, and custom tags may not be supported. For important configuration files, also verify the conversion result with your own tooling.
Security note
In some languages, loading YAML from an untrusted source with the general-purpose loader can lead to code execution; use “safe load” functions. Avoid storing passwords and keys as plain text in YAML files.
Multiline text
There are two notations for long text:
description: |
First line
Second line
The pipe (|) preserves line breaks; the greater-than sign (>) folds lines into a single line. This feature does not exist in JSON and makes configuration files readable.
Example: configuration conversion
If, under server:, it says port: 8080 and debug: false, the JSON equivalent is {"server": {"port": 8080, "debug": false}}. Note that the port is written without quotes: YAML reads this as a number; if you write "8080", it becomes text. This difference causes an error if it does not match the type your application expects.
The validation habit
Before saving a YAML file, running it through a validator or converting it to JSON catches indentation errors. If the conversion fails, look at the line of the error; most of the time a list's indentation is missing. In Kubernetes or CI files, a single wrong indentation can make the entire deployment fail.
When YAML, when JSON?
YAML for configurations that people will edit; JSON is safer for data exchange between programs. A need for comments favors YAML, while a need for a strict, unambiguous structure favors JSON.
Frequently asked questions
Can tabs be used in YAML?
No; only spaces are used for indentation, and tab characters cause an error.
Why does the value “NO” become false in YAML?
In older YAML versions, yes/no and on/off are converted to booleans; write such text in quotes.
What is the difference between YAML and JSON?
YAML uses indentation and supports comments; JSON builds structure with brackets and does not support comments.
Tools mentioned in this guide
More guides
- What Is JSON? Structure, Formatting, Validation and Finding Errors – What is JSON and how do you read and validate it? A nested example, a valid/invalid comparison table, number and date traps and the formatting difference.
- What Are JSON, Base64 and URL Encoding? Encoding vs Encryption vs Hashing – What do JSON, Base64, URL encoding, HTML entities, SHA and JWT do? Encoding vs encryption vs hashing, with examples that were run and verified.
- What Is Semver? MAJOR.MINOR.PATCH Version Numbers and ^ ~ Ranges – What is semantic versioning (semver)? MAJOR.MINOR.PATCH bump rules, pre-release ordering, ^ and ~ ranges and which version gets installed, with examples.
- What Is XML? The Difference Between XML and JSON, and How to Convert – What is XML, and what are its syntax rules? Differences between XML and JSON, how to choose between them, and examples of converting XML to JSON.
- What Is curl? Basic Flags and Converting a curl Command to fetch – What is curl and what do the -X, -H and -d flags do? A POST request example, the JavaScript fetch equivalent of a curl command, and debugging tips.
This article is for general information only and is not legal, financial or medical advice. We are not an official institution.