How to use the YAML to JSON
- Paste YAML or drop a .yml/.yaml file.
- Read any parse error: it points to the line where indentation or syntax broke.
- Check the JSON for values whose type surprised you (see the table below).
- Copy or download the JSON.
Worked example
A deploy config using a comment and an anchor
YAML
# deploy config
app: web
replicas: 3
env:
- name: LOG_LEVEL
value: info
base: ®ion eu-west-1
backup: *regionJSON
{
"app": "web",
"replicas": 3,
"env": [
{
"name": "LOG_LEVEL",
"value": "info"
}
],
"base": "eu-west-1",
"backup": "eu-west-1"
}The comment is dropped (JSON has none) and the alias *region is replaced by the anchored value.
Unquoted YAML values and the JSON they produce
Results under the YAML 1.2 core schema. Older 1.1 parsers differ on some rows.
| YAML | JSON | Watch out |
|---|---|---|
| port: 8080 | 8080 | |
| debug: true | true | |
| answer: yes | "yes" | true in YAML 1.1 parsers |
| version: 1.10 | 1.1 | Quote it to keep "1.10" |
| value: ~ | null | Empty value also means null |
| date: 2026-10-29 | "2026-10-29" | Some parsers return a date object |
Common YAML errors
Tabs are not allowed for indentation; replace them with spaces. A key indented one space less than its siblings ends the parent mapping early. A colon followed by a space inside an unquoted value, as in title: Note: read me, starts a new mapping – quote the value.
Multiple documents
A file can hold several YAML documents separated by ---, as Kubernetes manifests often do. JSON has a single root, so multi-document input converts to a JSON array with one element per document.
Custom tags such as !Ref in CloudFormation are not part of core YAML; they have no JSON equivalent and may be rejected or kept as plain values.
YAML to JSON FAQ
How do I convert YAML to JSON on the command line?
With yq v4: yq -o=json file.yaml. With Python and PyYAML: python -c 'import sys,yaml,json; print(json.dumps(yaml.safe_load(sys.stdin)))' < file.yaml.
Why does my YAML fail to parse?
Most often a tab used for indentation, inconsistent indent levels, or an unquoted value containing ": " or starting with a special character like @, * or &. The error line points to where the parser gave up.
What happens to YAML comments when converting to JSON?
They are removed. JSON has no comment syntax, so there is nowhere to keep them.
How are YAML anchors and aliases converted?
Each alias is replaced with a full copy of the anchored value, so the JSON may be larger than the YAML.
Is YAML a superset of JSON?
YAML 1.2 is designed to be, so JSON is valid YAML. The reverse is not true: comments, anchors and multiple documents have no JSON form.

