How to convert YAML to JSON
- Paste YAML into the left box, drop a .yaml or .yml file on it, or press Upload.
- Valid YAML is converted as you type. If there is a mistake, the status line names it and gives the line and column; Show in input jumps there.
- Pick the JSON indentation (2 spaces, 4 spaces, tabs or minified), then Copy or Download .json.
YAML to JSON example
A Docker Compose style file with a comment, an anchor (&base) and merge keys (<<: *base):
# shared settings
x-base: &base
restart: always
environment:
TZ: UTC
services:
web:
<<: *base
image: nginx:1.27
ports: ["8080:80"]
worker:
<<: *base
image: shop/worker:3
replicas: 2converts to the JSON below. The comment is gone, and each service gets its own full copy of the shared settings:
{
"x-base": {
"restart": "always",
"environment": {
"TZ": "UTC"
}
},
"services": {
"web": {
"restart": "always",
"environment": {
"TZ": "UTC"
},
"image": "nginx:1.27",
"ports": [
"8080:80"
]
},
"worker": {
"restart": "always",
"environment": {
"TZ": "UTC"
},
"image": "shop/worker:3",
"replicas": 2
}
}
}The x-base block itself stays in the output because it's an ordinary key. To explore a long result, open it in the JSON viewer.
Fixing YAML errors
Most YAML errors are about indentation. Here, port has three spaces instead of two:
server:
host: example.com
port: 8080The converter stops with: Invalid YAML: bad indentation of a mapping entry (line 3, column 8). Other common ones:
- Tabs: a tab used for indentation gives "tab characters must not be used in indentation" (line 2). YAML only allows spaces.
- Duplicate keys: writing
name:twice in one mapping gives "duplicated mapping key" (line 2). JSON parsers would silently keep the last one; YAML treats it as an error. - Unquoted colons: a value like
title: Note: read meneeds quotes:title: "Note: read me".
Multi-document YAML to JSON
Kubernetes manifests often hold several documents separated by ---. They become a JSON array, one item per document:
---
kind: Service
metadata: { name: web }
---
kind: Deployment
metadata: { name: web }[{"kind":"Service","metadata":{"name":"web"}},{"kind":"Deployment","metadata":{"name":"web"}}]How YAML types become JSON
The converter uses the YAML 1.2 core schema, the current standard, so only unambiguous values change type:
enabled: yes
debug: false
version: 1.10
released: 2026-09-25
port: 8080
owner: ~{
"enabled": "yes",
"debug": false,
"version": 1.1,
"released": "2026-09-25",
"port": 8080,
"owner": null
}yesstays a string: in YAML 1.2 onlytrue/falseare booleans.1.10is a number, so it becomes1.1. Quote version numbers in YAML ("1.10") to keep them exact.- Dates stay strings, because JSON has no date type.
~andnullbecome null. .infand.nanhave no JSON form and become null, with a warning.
What is not kept
Comments, anchor names, quoting style and blank lines are YAML presentation, and JSON has no place for them. Key order and all values are kept. Converting back with the JSON to YAML converter gives clean, equivalent YAML, but without the comments. To tidy or check the JSON itself, format and validate the JSON.
On the command line, yq -o json file.yaml or python -c 'import sys, json, yaml; json.dump(yaml.safe_load(sys.stdin), sys.stdout, indent=2)' < file.yaml do the same job (PyYAML follows YAML 1.1, so yes becomes true there).
Frequently asked questions
How do I convert YAML to JSON?
Paste the YAML into the left box or upload a .yaml or .yml file. Valid YAML is converted to formatted JSON as you type; invalid YAML shows the error with its line and column. Copy the JSON or download it as a .json file.
What does "bad indentation of a mapping entry" mean?
A key is indented by a different number of spaces than the keys next to it, so the parser cannot tell which object it belongs to. Line up keys at the same level with exactly the same number of spaces. Press "Show in input" to jump to the line.
Can I use tabs in YAML?
No. YAML does not allow tab characters for indentation, only spaces. Replace the tabs with spaces (2 per level is usual) and the error goes away.
Are YAML comments kept in the JSON?
No. JSON has no comment syntax, so lines starting with # are dropped. Keep the YAML file as the source if the comments matter.
What happens to anchors, aliases and merge keys?
They are expanded. Each *alias is replaced by a full copy of the anchored value, and <<: merge keys are merged into the mapping, because JSON has no way to refer to another part of the document.
How is a YAML file with several documents converted?
A file with several documents separated by --- becomes a JSON array with one item per document, in order. A file with one document becomes that document on its own.
Why is "yes" converted to a string and not true?
The converter follows YAML 1.2, the current version, where only true and false are booleans. yes, no, on and off are booleans only in YAML 1.1, so some older tools (for example PyYAML) read them differently. Quote values in the YAML if you need to be sure.
Is YAML a superset of JSON?
Practically yes. Since YAML 1.2, valid JSON is also valid YAML, so you can paste JSON here and get it back formatted.
Is my YAML uploaded or stored?
No. The YAML is parsed in your browser, and nothing is sent to a server or saved. That makes it safe for config files that contain internal hostnames, but remove real passwords and keys before pasting secrets anywhere.