FYI (now that I am on this group) I uploaded Mojo::JSON::MaybeXS a while back also based on sri's earlier post, which will use the fallback behavior of JSON::MaybeXS and default to Cpanel::JSON::XS. On a related note Cpanel::JSON::XS has recently fixed the handling of upgraded numbers and inf/nan so if you have the newest version it works even better.
https://metacpan.org/pod/Mojo::JSON::MaybeXS On Tuesday, November 25, 2014 10:32:34 AM UTC-5, sri wrote: > > 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. > > perl -MMojo::JSONXS -Mojo -E 'say > app->build_controller->render_to_string(json => {foo => "/bar/baz", yada => > Mojo::JSON->true})' > > -- > sebastian > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
