http://qs321.pair.com?node_id=1213000

1nickt has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

My understanding is that using JSON will cause Perl to load JSON::XS or Cpanel::JSON::XS if they are installed. But my testing shows that JSON::PP is used:

$ perl -MJSON -e 1 $ perl -MJSON::XS -e 1 Can't locate JSON/XS.pm in @INC (you may need to install the JSON::XS +module) [...] BEGIN failed--compilation aborted. $ perl -MCpanel::JSON::XS -e 1 $ perl -MJSON -MData::Dumper -wE 'decode_json(qq{{"foo":"bar"}}); say +Dumper %INC;' | grep JSON $VAR33 = 'JSON/PP.pm'; $VAR34 = '/Users/ntonkin/perl5/perlbrew/perls/perl-5.26.1/lib/5.26.1/J +SON/PP.pm'; $VAR37 = 'JSON.pm'; $VAR38 = '/Users/ntonkin/.perlbrew/libs/perl-5.26.1@dev/lib/perl5/JSON +.pm';

Anything I have missed?


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re: JSON not loading Cpanel::JSON::XS
by dasgar (Priest) on Apr 16, 2018 at 15:52 UTC

    If you have Cpanel::JSON::XS installed and want JSON to use that module, you might want to look at the Choosing Backend section of JSON's documentation, which provides instructions on how to specify a backend module to use.

      Awesome, thanks! RTFM, I guess! So JSON will automatically load JSON::XS if installed, but you have to specify Cpanel::JSON::XS if you want it with PERL_JSON_BACKEND=Cpanel::JSON::XS ...


      The way forward always starts with a minimal test.
Re: JSON not loading Cpanel::JSON::XS
by Haarg (Priest) on Apr 17, 2018 at 10:04 UTC

      Thanks Haarg! I was pretty sure one could leave it up to the module; just didn't remember which module!


      The way forward always starts with a minimal test.