-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide type support when decoding JSON string
JSON decoder fills optional third argument of Cpanel::JSON::XS::decode_json function and optional second argument of ->decode method with original JSON types from input string. Examples: my $value = decode_json('false', 1, my $type); $value is 0 and $type is JSON_TYPE_BOOL my $value = decode_json('0', 1, my $type); $value is 0 and $type is JSON_TYPE_INT my $value = decode_json('"0"', 1, my $type); $value is 0 and $type is JSON_TYPE_STRING my $struct = Cpanel::JSON::XS->new->decode('[null,1,1.1,"1",[0],true]', my $type); $struct is [undef, 1, 1.1, '1', [0], 1] $value is [JSON_TYPE_NULL, JSON_TYPE_INT, JSON_TYPE_FLOAT, JSON_TYPE_STRING, [JSON_TYPE_INT], JSON_TYPE_BOOL] This allows users to correctly distinguish between booleans, integers, floats and strings in Perl language where perl interpreter can coerce between these types at any time.
- Loading branch information
Showing
3 changed files
with
193 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.