YAML 1.1 or 1.2?
The two versions of YAML read some unquoted values differently. YAML 1.2 (the default here, and in most JavaScript, Go and Rust parsers) reads no, on and yes as text and 0755 as 755. YAML 1.1, still used by PyYAML, Ruby and many CI systems, reads them as booleans and as the octal number 493. Choose the version your program's parser uses; the notes list every value the other version would read differently.
How to use the YAML to JSON
- Paste YAML, or press Sample.
- Choose the YAML version your parser uses.
- Read the notes for values that might not mean what you expect.
- Copy or download the JSON.
Examples
Docker Compose service
services:
web:
image: nginx:1.27
ports:
- "8080:80"
environment:
DEBUG: "false"
WORKERS: 4
{
"services": {
"web": {
"image": "nginx:1.27",
"ports": [
"8080:80"
],
"environment": {
"DEBUG": "false",
"WORKERS": 4
}
}
}
}
Values YAML 1.1 reads differently
country: NO
mode: 0755
{
"country": false,
"mode": 493
}
With YAML 1.2, the same input gives "NO" and 755. Quote values like these to make them mean the same everywhere.
Merge keys
defaults: &defaults
retries: 3
timeout: 30
production:
<<: *defaults
timeout: 60
{
"defaults": {
"retries": 3,
"timeout": 30
},
"production": {
"retries": 3,
"timeout": 60
}
}
production gets retries from defaults, and its own timeout overrides the merged one.
Anchors, aliases and merge keys
&name marks a value, *name repeats it, and <<: *name merges a mapping's keys into another, with the mapping's own keys taking priority. JSON has none of these, so the values are copied in full, as your program would see them.
Options
- YAML version
- 1.2 (the default) or 1.1, to match your parser. Merge keys are supported in both.
- Indent
- 2 spaces, 4 spaces or minified JSON.
Limitations
- Custom tags (such as
!Refin AWS CloudFormation) are read as plain values, without their tag. - YAML 1.1 timestamps are kept as the text written, because JSON has no date type.
.infand.nanbecomenull, because JSON can't represent them.
Frequently asked questions
Is my YAML uploaded?
No. The conversion runs in your browser; nothing you paste is sent anywhere.
Why did my version number change?
Unquoted, version: 1.10 is a number, which most programs store as 1.1. The JSON keeps the digits as written, but quote version numbers in YAML ("1.10") to keep them as text.
Can it convert several documents?
Yes. A file with several documents separated by --- becomes a JSON array with one element per document.
How do I convert JSON to YAML?
Use the JSON to YAML converter.