sherab has asked for the wisdom of the Perl Monks concerning the following question:

Hi folks. This is a modification to my previous question, only slightly different and apologies if I should have altered the original. The original is here: http://www.perlmonks.org/?node_id=991672 (and public thanks to Remiah for pointing me in the right direction). All is working fine with the code until I throw more than one item at it and then I get

Naughty! $: array value found, but a object is required

The script is below.....
#!/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"; }
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)

Replies are listed 'Best First'.
Re: Validating a JSON structure: Part Deux
by daxim (Curate) on Sep 05, 2012 at 18:10 UTC
    I didn't run your code, I want to point out some alternatives: Kwalify, Data::Rx
      Thanks! Kwalify looks especially intriguing.