YAML Syntax Validator Script
I've been tasked with creating and editing quite a few YAML files, but rather than using an online syntax validator, I'm looking to run it through a script. Are there any available scripts that will test YAML Syntax? I found one through Perl that used perl::xs, but it wasn't particularly portable.
You should try YAML on CPAN, which is pure perl without dependencies, so it's portable. You can even just download it and put them with your validator script without installation.
Here is a example validator script:
use YAML qw(LoadFile); use Data::Dumper; my $data = LoadFile($ARGV); print Dumper($data);
If any error occurred, the error message will tell you where's the problem:
YAML Error: Expected separator '---' Code: YAML_PARSE_ERR_NO_SEPARATOR Line: 1 Document: 2 at /Users/alec/perl5/perlbrew/perls/p5161t/lib/site_perl/5.16.1/YAML/Loader.pm line 81.