Other ways to convert YAML to JSON
- 1
yq (command line)
yq -o=json input.yaml > output.json. This is Mike Farah's Go version of yq (brew install yq); the older Python yq uses different options.
- 2
Python
python3 -c "import yaml,json,sys; print(json.dumps(yaml.safe_load(sys.stdin), indent=2, default=str))" < input.yaml > output.json. Needs pip install pyyaml. The default=str part stops dates from crashing the command. For a file with several --- documents, use yaml.safe_load_all and wrap the result in a list.
- 3
Node.js
With js-yaml installed: node -e "const y=require('js-yaml'),fs=require('fs'); console.log(JSON.stringify(y.load(fs.readFileSync('input.yaml','utf8')),null,2))" > output.json
- 4
Check the result
Comments are gone, since JSON has no comments, and anchors (&) and aliases (*) are expanded into full copies.
Why convert YAML to JSON?
YAML is written by humans configuring infrastructure; JSON is consumed by machines processing data. Converting between them is a routine operation in DevOps and API workflows — both formats describe the same structure in different syntax.
Frequently asked questions
How do I convert YAML to JSON on the command line?
Are YAML comments preserved in the JSON output?
How do YAML anchors and aliases convert to JSON?
No account. No upload. Works in any browser.