Validating YAML using CLI

Published
Updated

Sometimes you just want to check to see if a YAML file is correct and you don’t want to have to open it up on your IDE or install tools just so you can see if it is valid. The following command will quickly parse and validate even the largest YAML configuration files.

ruby -e "require 'yaml';puts YAML.load_file('./path_to_your_file.yaml')"

If you file is correct and valid, it will print out all of the keys and values. However, if you file is invalid it will give you the line number and character position of the error located within your YAML file:

Validating for errors on yaml file line number containing the error