Provide type support when decoding JSON string#115
Merged
Conversation
Owner
|
Can you also the missing JSON_TYPE_NULL pod? pod_coverage complains |
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.
Contributor
Author
|
Now I extended POD documentation. |
Owner
|
Great. But I cannot release this before my holidays, starting tommorow. I believe I'll have no wifi in the French Alps |
rurban
approved these changes
Aug 19, 2018
Owner
|
Released 4.05 without WiFi, only Phone hotspot. Thanks for the Glasgow talk! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JSON decoder fills optional third argument of
Cpanel::JSON::XS::decode_jsonfunction and optional second argument of->decodemethod with original JSON types from input string.Examples:
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.