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)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.