- DESIGN CONSIDERATION
- SEE ALSO
- COPYRIGHT AND LICENSE
JSON::XS::ByteString - A more predictable and convenient XS implementation for JSON
use JSON::XS::ByteString qw(encode_json encode_json_unblessed decode_json decode_json_safe); $json_string = encode_json($perl_data); $perl_data = decode_json($json_string); $perl_data = decode_json($json_string, 1); # die if $json_string is not valid JSON string $json_string = encode_json_unblessed($perl_data); # the same behavior as encode_json # but encode blessed references as reference strings, # like 'Object=HASH(0xffffffff)'
This module is a XS implementation for JSON. It provide a more predictable behavior than JSON::XS by always producing strings in JSON for normal scalars. And you can force it to produce numbers in JSON by putting references to numbers.
All the string data are treated as UTF-8 octets and just copy them in and out directly, except
\ and characters that
ord($char) < 32
decode_json will return an undef without exceptions with invalid json string.
Because in the pure Perl world, there's insignificant difference between numeric or string. So I think we don't need to do it since the result will be used in Perl.
json_decode preserve the identical structure as it received.
Get a JSON string from a perl data structure. Treat blessed objects as normal references.
Get a JSON string from a perl data structure. Treat blessed objects as strings (such as
Get the perl data structure back from a JSON string.
If the given string is not a valid JSON string, it will return an
undef. If the
$warn2die is false or not specified, this function will not die but warns an offset where it encountered the unrecognized character. If the
$warn2die is true, this function will die with the error message which is identical to the warning one.
The same as
decode_json except that
decode_json_safe will not warn at all.
This mod's github repository https://github.com/CindyLinz/Perl-JSON-XS-ByteString
Cindy Wang (CindyLinz)
Copyright (C) 2014-2020 by Cindy Wang (CindyLinz)
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8 or, at your option, any later version of Perl 5 you may have available.