JSON::TypesVariable type utility for JSON encoding | |
Download |
JSON::Types Ranking & Summary
Advertisement
- License:
- Perl Artistic License
- Price:
- FREE
- Publisher Name:
- Daisuke Murase
- Publisher web site:
- http://search.cpan.org/~typester/
JSON::Types Tags
JSON::Types Description
The type mappings between JSON and Perl is annoying things. For example, use JSON; my $number = 123; warn " number:$number\n" if $ENV{DEBUG}; print encode_json();Output of this code depends on whether DEBUG environment is set or not. If set, result is . If not to set, result is . This is normal behaviour on Perl though, it sometimes causes unexpected JSON results.There is a solution about this: print encode_json();This code always outputs . But the code is a bit ugly and not readable at all.JSON::Types is a Perl module that provides some functions to fix this variable types issue: number $foo; # is always number string $foo; # is always string bool $foo; # is always boolYou can fix above code by using this module like this: use JSON; use JSON::Types; my $number = 123; warn " number:$number\n" if $ENV{DEBUG}; print encode_json();SYNOPSIS # Export type functions by default use JSON; use JSON::Types; print encode_json({ number => number "123", string => string 123, bool => bool "True value", }); # => {"number":123,"string":"123","bool":true} # Non export interface use JSON::Types (); print encode_json({ number => JSON::Types::number "123", string => JSON::Types::string 123, bool => JSON::Types::bool "True value", });Product's homepage
JSON::Types Related Software