sherab has asked for the wisdom of the Perl Monks concerning the following question:
I have tried placing the object param all over the place and still no luck. Otherwise this module is the answer to my non-denominational prayers for JSON testing. (Thank you Tobyink if you're lurking in here somewhere)#!/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}, }, additionalProperties => 0 }; my $test = to_json([ { year => '1999', month => '11' }, { year => '1998', month => '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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Validating a JSON structure: Part Deux
by daxim (Curate) on Sep 05, 2012 at 18:10 UTC | |
by sherab (Scribe) on Sep 05, 2012 at 20:31 UTC |