There's a lot of modules for this already on CPAN, sadly most of them are terrible, it would be great if someone released one that actually worked most of the time.
package Mojo::JSONXS;
use Cpanel::JSON::XS;
use Mojo::JSON;
use Mojo::Util 'monkey_patch';
my $BINARY = Cpanel::JSON::XS->new->utf8(1)->allow_nonref(1)->allow_blessed(1)
->convert_blessed(1);
my $TEXT = Cpanel::JSON::XS->new->utf8(0)->allow_nonref(1)->allow_blessed(1)
->convert_blessed(1);
monkey_patch 'Mojo::JSON', 'encode_json', sub { $BINARY->encode(shift) };
monkey_patch 'Mojo::JSON', 'decode_json', sub { $BINARY->decode(shift) };
monkey_patch 'Mojo::JSON', 'to_json', sub { $TEXT->encode(shift) };
monkey_patch 'Mojo::JSON', 'from_json', sub { $TEXT->decode(shift) };
monkey_patch 'Mojo::JSON', 'true', sub { Cpanel::JSON::XS::true() };
monkey_patch 'Mojo::JSON', 'false', sub { Cpanel::JSON::XS::false() };
1;
It's not even very hard, this one for example should cover pretty much all use cases.