Skip to content

Instantly share code, notes, and snippets.

@zigorou
Last active August 29, 2015 13:56
Show Gist options
  • Save zigorou/9090445 to your computer and use it in GitHub Desktop.
Save zigorou/9090445 to your computer and use it in GitHub Desktop.
{
"type": "object",
"properties": {
"id": {
"type": "integer",
"minimum": 1
},
"name": {
"type": "string",
"pattern": "^[A-Za-z0-9_]{1,32}$"
}
}
}
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw(say);
use Data::Dumper qw(Dumper);
use File::Slurp qw(slurp);
use JSON;
use JSV::Validator;
my $json = JSON->new->allow_nonref(1);
my $jsv = JSV::Validator->new;
my $schema_json = slurp($ARGV[0]);
my $schema = $json->decode($schema_json);
my $instance = $json->decode(do {
local $/;
<STDIN>
});
my $result = $jsv->validate($schema, $instance);
if ($result) {
say "valid";
}
else {
say Dumper($result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment