#!/usr/bin/perl use JSON; use JSON::Schema; # Here's a structure to validate against... my $json_model ={ type => 'object', properties => { year => {type=>'number', minimum=>0, maximum=>9999}, month => {type=>'number', minimum=>1, maximum=>12}, } }; #And now here's some bad data. monkeys do not belong (silly monkeys!) my $test = to_json({ year => '1999', monkeys => '10' }); my $validator = JSON::Schema->new($json_model); # Validate: my $valid = $validator->validate($test); if ($valid) { print "Yay!\n"; exit; } # But it's not valid... foreach my $e ($valid->errors) { print "Naughty! $e\n"; }