JSON::MaybeUTF8(3)
π JSON::MaybeUTF8 β NAME β¨
okay bestie, so this is the JSON::MaybeUTF8 manual page (it's JSON::MaybeUTF8(3), living in the User Contributed Perl Documentation section, iykyk) β and it's literally just here to give you explicit text/UTF-8 JSON functions. That's the whole vibe. Explicit. No guessing. Periodt. π
πΈ SYNOPSIS πΈ
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 => '...' }));
like, look at that. STDOUT gets :encoding(UTF-8), STDERR gets :raw, and then each one gets the right encoder for its vibe. that's the entire point, bestie π«Ά
π¦ DESCRIPTION π¦
So this module combines JSON::MaybeXS with Unicode::UTF8 to hand you 4 functions that cover all the combinations of JSON and UTF-8 encoding/decoding. all four combos. every single one. no gaps π₯
The idea (and honestly it's giving main character energy) is to make the UTF-8-or-not behaviour more explicit in code that deals with multiple transport layers β think database, cache and I/O. When you've got layers stacked on layers, you want zero ambiguity about which encoding is which. ngl that's the whole mood.
And yes, it's a trivial wrapper around two other modules. it's not doing anything wild, it's just being clear about it. iconic.
π BOM removal π
The $JSON::Maybe::UTF8::REMOVE_BOM flag is set by default, and the reason is <https://github.com/rurban/Cpanel-JSON-XS/issues/125>. like, that's just how it is.
If you'd rather disable it, just drop this in your code:
$JSON::Maybe::UTF8::REMOVE_BOM = 0;
β οΈ heads up bestie: this only affects things whenCpanel::JSON::XSis used β and that's the oneJSON::MaybeXSprefers if it can be loaded. so if it's not loaded, this flag is lowkey not doing anything for you π
π decode_json_utf8 π
You give it a UTF-8-encoded JSON byte string, it gives you back a Perl data structure. it may optionally remove the UTF-8 BOM β <https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8> β if it exists. if there's no BOM, no drama π
β encode_json_utf8 β
You give it a Perl data structure, it gives you back a UTF-8-encoded JSON byte string. slay.
π§ decode_json_text π§
You give it a JSON string composed of Unicode characters (that's in Perl's internal encoding, for the record), it gives you back a Perl data structure. β¨
π encode_json_text π
You give it a Perl data structure, it gives you back a JSON string composed of Unicode characters (again β Perl's internal encoding). π
π encode_json_text π (yes, it's listed twice π)
okay so the source lists encode_json_text a second time here, and this one is doing something a little different, so listen up:
You give it a Perl data structure, and you get back a formatted JSON string composed of Unicode characters (Perl's internal encoding, same as before).
It's functionally identical to encode_json_text, but with indentation to make it readable π β and with defined key ordering, which should make it easier to diff two different data structures. honestly? diffable JSON is a love language. obsessed.
π AUTHOR π
Tom Molesworth <TEAM@cpan.org>
π LICENSE π
Copyright Tom Molesworth 2017-2021. Licensed under the same terms as Perl itself.
and that's the whole page, bestie π β brought to you by perl v5.42.2, dated 2026-02-15. go forth and encode explicitly πβ¨
π¦ where this page comes from
- alpine 3.24: perl-json-maybeutf8-doc 2.000-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms