JSON::MaybeUTF8 - provide explicit text/UTF-8 JSON functions
use JSON::MaybeUTF8 qw(:v1); binmode STDOUT, ':encoding(UTF-8)'; binmode STDERR, ':raw'; (*STDOUT)->print(encode_json_text({ text => '...' })); (*STDERR)->print(encode_json_utf8({ text => '...' }));
Combines JSON::MaybeXS with Unicode::UTF8 to provide 4 functions that handle the combinations of JSON and UTF-8 encoding/decoding.
The idea is to make the UTF-8-or-not behaviour more explicit in code that deals with multiple transport layers such as database, cache and I/O.
This is a trivial wrapper around two other modules.
The $JSON::Maybe::UTF8::REMOVE_BOM flag is set by default due to https://github.com/rurban/Cpanel-JSON-XS/issues/125. If you would prefer to disable this, add $JSON::Maybe::UTF8::REMOVE_BOM = 0; in your code.
$JSON::Maybe::UTF8::REMOVE_BOM
$JSON::Maybe::UTF8::REMOVE_BOM = 0;
Note that this only affects things when Cpanel::JSON::XS is used (preferred by JSON::MaybeXS if it can be loaded).
Given a UTF-8-encoded JSON byte string, returns a Perl data structure. May optionally remove the UTF-8 BOM if it exists.
Given a Perl data structure, returns a UTF-8-encoded JSON byte string.
Given a JSON string composed of Unicode characters (in Perl's internal encoding), returns a Perl data structure.
Given a Perl data structure, returns a JSON string composed of Unicode characters (in Perl's internal encoding).
Tom Molesworth <TEAM@cpan.org>
Copyright Tom Molesworth 2017. Licensed under the same terms as Perl itself.
To install JSON::MaybeUTF8, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JSON::MaybeUTF8
CPAN shell
perl -MCPAN -e shell install JSON::MaybeUTF8
For more information on module installation, please visit the detailed CPAN module installation guide.