Output will appear here
Output will appear here
Paste YAML and get the same data as JSON, indented with two spaces. Comments are dropped, | and > block scalars become strings with \n, and flow collections like [a, b] and {x: 1} are parsed. It follows YAML 1.2: only true and false are booleans, so yes, no, on and off stay strings. Anchors, aliases and << merge keys are expanded, and a file with several --- documents becomes a JSON array.
By Ankit Aglawe · Updated · Runs entirely in your browser
The comment disappears. CACHE: on stays the string "on" under YAML 1.2; write true if you mean a boolean. The port mapping is quoted in the source, so it stays the string "8080:80", and 10s is a plain string.
# docker-compose.yml
services:
api:
image: "ghcr.io/acme/api:2.4"
ports: ["8080:80"]
environment:
LOG_LEVEL: info
CACHE: on
REGION: "no"
depends_on: [db]
db:
image: postgres:16
restart: unless-stopped
healthcheck:
retries: 5
interval: 10s{
"services": {
"api": {
"image": "ghcr.io/acme/api:2.4",
"ports": [
"8080:80"
],
"environment": {
"LOG_LEVEL": "info",
"CACHE": "on",
"REGION": "no"
},
"depends_on": [
"db"
]
},
"db": {
"image": "postgres:16",
"restart": "unless-stopped",
"healthcheck": {
"retries": 5,
"interval": "10s"
}
}
}
}The on key stays the string "on". A YAML 1.1 parser such as PyYAML would turn it into true, which is why some tools report a true key here. The run: | block becomes one string with a \n between commands and a single trailing newline.
name: CI
on:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Run tests
run: |
npm ci
npm test{
"name": "CI",
"on": {
"push": {
"branches": [
"main"
]
}
},
"jobs": {
"test": {
"runs-on": "ubuntu-latest",
"timeout-minutes": 10,
"steps": [
{
"uses": "actions/checkout@v4"
},
{
"name": "Run tests",
"run": "npm ci\nnpm test\n"
}
]
}
}
}These stay strings, as YAML 1.2 says. Only true, false (also True/TRUE) are booleans, and null, Null, ~ or an empty value are null. YAML 1.1 parsers such as PyYAML and go-yaml v2 read yes/no/on/off as booleans, so write true/false if the file is read by both.
&base and *base are expanded into full copies, and <<: *base merges the anchored map into the current one, with keys written alongside it taking priority. The JSON has no references, so a large anchor used many times makes a large output.
A file with more than one --- document, such as a multi-resource Kubernetes manifest, becomes a JSON array with one element per document. A single leading --- is just one document. Duplicate keys in one map are an error, not last-one-wins.
A bare 1.0 becomes the JSON number 1, so version: 1.10 turns into 1.1. Quote versions and zip codes. 0x1F and 0o17 are read as hex and octal, and 02134 becomes 2134. .inf has no JSON form and comes out as null.
| keeps line breaks and > folds lines into spaces, with a blank line becoming a \n. Both end with one newline by default, |- or >- strip it, and |+ keeps every trailing newline.
A # starts a comment only at the start of a line or after whitespace, and never inside quotes. So url: http://x.com/#top keeps its fragment, and # note at the end of a line is removed.
2024-01-15 is emitted as the string "2024-01-15", not converted to a timestamp. JSON has no date type, and this avoids the timezone shift some parsers add.
Double-quoted values understand the YAML escapes, including \n, \t, \", \\ and \u00e9. Single-quoted values are literal, and '' inside them is one apostrophe.
| YAML | JSON | Notes |
|---|---|---|
port: 5432 | 5432 | Number |
port: "5432" | "5432" | Quotes keep strings |
debug: true / yes | true / "yes" | YAML 1.2 booleans |
a: ~ / a: | null | Null |
<<: *base | Merged keys | Anchors expanded |
v: 1.0 | 1 | Quote versions |
mask: 0xFF | 255 | Hex and 0o octal |
items: [a, b] | ["a", "b"] | Flow sequence |
text: | | "line1\nline2\n" | Literal block |
text: > | "line1 line2\n" | Folded block |
Enter YAML data in the left editor. Block and flow collections, anchors and merge keys, block scalars and multi-document files are all supported.
The right pane shows the equivalent JSON with proper formatting. All YAML types are mapped to their JSON counterparts.
Copy the JSON to your clipboard or download it as a .json file. Use it in APIs, JavaScript applications, or anywhere JSON is expected.
Paste the YAML in the left pane. The JSON appears on the right, pretty-printed with two-space indentation, ready to copy or download.
This converter follows YAML 1.2, where only true and false are booleans. yes/no/on/off are YAML 1.1 booleans and stay strings here. Write true or false to get a JSON boolean.
No. JSON has no comment syntax, so every # comment is dropped during conversion.
Yes. Nested maps, lists indented or not (the kubectl style with the dash under the key), anchors, block scalars and multi-document manifests all convert. A file with several documents becomes a JSON array.
Unquoted 1.10 is a number in YAML, and as a number it equals 1.1. Write version: "1.10" to keep it exact.
No. Parsing happens in your browser tab.
Need several formats at once? Convert All shows every output from one paste. Or browse all JSON converters.