Hi, I have never heard of that module (<RANT>And I think modules should have sensible, descriptive names!</RANT>).

I tried using JSON::Validator but it doesn't seem to support "additionalProperties": "false" even with its latest version (also it requires installing the entire Mojolicious application, which I think is silly). JSON::Schema is even less up to date with newer JSON Schema versions, unfortunately, so I didn't try with that.

However, you can easily create a Type that will do what you want, using another of tobyink's creations, Type::Tiny:

use strict; use warnings; package MyTypes { use parent 'Type::Library'; use Type::Utils; use Types::Standard qw/ Dict Enum Str /; declare MyType => as Dict[ method => Enum['xxx'], backend => Dict[ client => Str, pw => Str, ], ]; }; package main { use JSON; MyTypes->import(qw/ +MyType /); my $data = from_json q|{ "method": "xxx", "backend": { "client": "mytest009", "pw": "sdkjfhsfjhKJH87" }, "blah": "123" }|; assert_MyType( $data ); }; __END__
Output:
Reference {"backend" => {"client" => "mytest009","pw" => "sdkjfhsfjhKJ +...} did not pass type constraint "MyType" at 1209129-2.pl line 31 "MyType" is a subtype of "Dict[backend=>Dict[client=>Str,pw=>Str], +method=>Enum["xxx"]]" Reference {"backend" => {"client" => "mytest009","pw" => "sdkjfhsf +jhKJ...} did not pass type constraint "Dict[backend=>Dict[client=>Str +,pw=>Str],method=>Enum["xxx"]]" "Dict[backend=>Dict[client=>Str,pw=>Str],method=>Enum["xxx"]]" doe +s not allow key "blah" to appear in hash

Hope this helps!


The way forward always starts with a minimal test.

In reply to Re: Brannigan: hash validation by 1nickt
in thread Brannigan: hash validation by henzen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.