How to Validate Yaml from the Command Line Using Python
This guide will show you how to validate yaml on the command line using Python.
Posted in these interests:
This guide will show you how to validate yaml on the command line using Python.
python -c 'import yaml, sys; yaml.safe_load(sys.stdin)' < cfg.yaml
If your file contains valid yaml, it will do nothing.
[tmp]$ python -c 'import yaml, sys; yaml.safe_load(sys.stdin)' < cfg.yaml
If the file does not contain valid yaml, you'll get a traceback. From that traceback you should be able to identify the problem.
[tmp]$ python -c 'import yaml, sys; yaml.safe_load(sys.stdin)' < cfg.yaml
Traceback (most recent call last):
File "<string>", line 1, in <module>
...
could not find expected ':'
in "<stdin>", line 5, column 1
The traceback contains a lot of lines that are very useful, but near the end you'll find the line number and column of the error.
Nothing says good morning quite like a breakfast sandwich. From the doughiness of the muffin to the eggs' fluffiness to the cheese's gooeyness, breakfast sandwiches are a great start to your morning.