How to validate the YAML file from command line

yaml

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?

Best Answer

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