Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

JSON not loading Cpanel::JSON::XS

by 1nickt (Monsignor)
on Apr 16, 2018 at 15:39 UTC ( #1213000=perlquestion: print w/replies, xml ) Need Help??
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 (Deacon) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1213000]
Approved by marto
Front-paged by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2018-11-20 19:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (231 votes). Check out past polls.

    Notices?