use strict; use warnings; package JSONTypes { use parent 'Type::Library'; use Type::Utils; use Types::Standard qw/ Dict Enum Str Tuple ArrayRef Optional RegexpRef Int /; declare JSONType => as Dict[ method => Enum[qw(xxx yyy)], backend => Dict[ num => Int, other => Optional[Str], StrMatch[qr/^[a-z0-9]+$/] ], # following works, but how to check that the array has at least (say) 2 elements - {2,} clientArr => ArrayRef[ Dict[ num => Int, ], ] ]; }; package main { use JSON; JSONTypes->import(qw/ +JSONType /); my $data = from_json q|{ "method": "xxx", "backend": { "num": 1, "client": "mytest009b" }, "clientArr": [{ "num": "1" }, { "num": "2" }] }|; my $ret = eval { assert_JSONType( $data ); }; if ($@) { print "ERROR\n$@\n"; } else { print "OK\n"; } };