How do I validate my YAML file from command line?

user375566 picture user375566 · Oct 19, 2010 · Viewed 86.1k times · Source

I am having issues pulling from a YAML config file:

Fatal error: while parsing a block mapping; expected <block end>, but found block entry

While there are plenty of online YAML validators, which I have tried and have helped, I'd like to validate my YAML files from the command line and integrate this into my continuous integration pipeline.

How can I validate the syntax of a YAML file on the command line?

Answer

Tombart picture Tombart · Dec 6, 2013

With basic Ruby installation this should work:

ruby -ryaml -e "p YAML.load(STDIN.read)" < data.yaml

Python version (thx @Murphy):

pip install pyyaml
python -c 'import yaml, sys; print(yaml.safe_load(sys.stdin))' < data.yaml