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:
Output: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__
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!
In reply to Re: Brannigan: hash validation
by 1nickt
in thread Brannigan: hash validation
by henzen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |