diff --git a/lib/WebGUI/Types.pm b/lib/WebGUI/Types.pm index 25e70df5b..3b7dec8ac 100644 --- a/lib/WebGUI/Types.pm +++ b/lib/WebGUI/Types.pm @@ -70,4 +70,18 @@ coerce 'WebGUI::Type::JSONArray' => via { return []; }, ; +subtype 'WebGUI::Type::JSONHash' + => as 'HashRef' +; + +coerce 'WebGUI::Type::JSONHash' + => from Str + => via { my $struct = eval { JSON::from_json($_); }; $struct ||= {}; return $struct; }, +; + +coerce 'WebGUI::Type::JSONHash' + => from Undef + => via { return {}; }, +; + 1;