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" => "sdkjfhsfjhKJ...} 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"]]" does not allow key "blah" to appear in hash