How to convert YAML to JSON
- Paste your YAML, open a
.yamlor.ymlfile, or click Load Sample. - Click Convert to JSON. The JSON appears on the right, indented with two spaces.
- Copy or download it. If the YAML has a mistake, the line turns red and the message explains what the parser expected.
How YAML maps to JSON
| YAML | JSON |
|---|---|
key: value blocks | Object |
- item lists | Array |
true, false, and also yes, no, on, off | true or false |
null, ~ or no value at all (key:) | null |
8080, 1.5 | Number |
2026-01-05 | The string "2026-01-05", kept exactly as written |
| block (keeps line breaks) | String with \n between lines |
> block (folds lines) | String with the lines joined by spaces |
&anchor and *alias | A full copy of the anchored value |
<<: *defaults | The keys of defaults merged into the object |
Several documents separated by --- | An array with one item per document |
# comments | Dropped, because JSON has no comments |
Anchors and merge keys
Docker Compose files, CI pipelines and Rails configs often reuse settings with anchors. This YAML:
defaults: &defaults
adapter: postgres
pool: 5
development:
<<: *defaults
database: app_dev becomes
{
"defaults": { "adapter": "postgres", "pool": 5 },
"development": { "adapter": "postgres", "pool": 5, "database": "app_dev" }
} Some online converters leave a literal "<<" key in the JSON. Here the merge is applied, so the JSON is what your application actually sees.
Values that change type
YAML guesses types from how a value looks, and the guess isn't always what you meant:
country: nobecomesfalse. Writecountry: "no"to keep the text.zip: 01701is read as an octal number and becomes961. Quote ZIP codes, phone numbers and IDs with leading zeros.version: 1.10becomes the number1.1. Quote version numbers.
If a value comes out different from what you expected, quoting it in the YAML is almost always the fix.
OpenAPI, Swagger and Kubernetes files
OpenAPI and Swagger specs are usually written in YAML, but some tools only import JSON. Paste the spec here, convert it and save the result as openapi.json. The same works for Kubernetes manifests: a file with several resources separated by --- becomes a JSON array with one object per resource.
Converting YAML to JSON in code
# Python (pip install pyyaml)
import json, yaml
with open('config.yaml') as f:
print(json.dumps(yaml.safe_load(f), indent=2))
// Node.js (npm install js-yaml)
const yaml = require('js-yaml');
const json = JSON.stringify(yaml.load(fs.readFileSync('config.yaml', 'utf8')), null, 2);
# Command line with yq
yq -o=json config.yaml Frequently asked questions
Is my YAML stored?
No. The YAML is sent to our server only to be converted and is not saved or logged. The result comes straight back to your browser.
Does it support anchors, aliases and merge keys?
Yes. &anchor and *alias are replaced with a copy of the value, and <<: *name merges that mapping's keys into the object, so the JSON matches what your application loads.
What happens to YAML comments?
They are dropped. JSON has no comment syntax, so there is nowhere to put them.
Why did yes or no turn into true or false?
YAML 1.1 parsers, which most tools still use, read yes, no, on and off as booleans. Put the value in quotes to keep it as text.
Can it convert a file with several documents?
Yes. Documents separated by --- become a JSON array with one item per document, in the same order.