Last active
August 29, 2015 13:56
-
-
Save zigorou/9090445 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "object", | |
"properties": { | |
"id": { | |
"type": "integer", | |
"minimum": 1 | |
}, | |
"name": { | |
"type": "string", | |
"pattern": "^[A-Za-z0-9_]{1,32}$" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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