Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How do I tell if my code is using JSON::PP or JSON::XS?

by perlfan (Vicar)
on Nov 19, 2020 at 05:47 UTC ( [id://11123814]=note: print w/replies, xml ) Need Help??


in reply to How do I tell if my code is using JSON::PP or JSON::XS?

> I thought that ‘use JSON’ would detect the availability of the XS module and use it if possible, is that correct?

I believe you're thinking of JSON::MaybeXS.

This module first checks to see if either Cpanel::JSON::XS or JSON::XS (at at least version 3.0) is already loaded, in which case it uses that module. Otherwise it tries to load Cpanel::JSON::XS, then JSON::XS, then JSON::PP in order, and either uses the first module it finds or throws an error.

Also please post some representational code, if you're hitting a bottleneck it could be a million different things.

  • Comment on Re: How do I tell if my code is using JSON::PP or JSON::XS?

Replies are listed 'Best First'.
Re^2: How do I tell if my code is using JSON::PP or JSON::XS?
by marto (Cardinal) on Nov 19, 2020 at 06:20 UTC

    Did you look at the JSON docs?

    "This module is a thin wrapper for JSON::XS-compatible modules with a few additional features. All the backend modules convert a Perl data structure to a JSON text and vice versa. This module uses JSON::XS by default, and when JSON::XS is not available, falls back on JSON::PP, which is in the Perl core since 5.14. If JSON::PP is not available either, this module then falls back on JSON::backportPP (which is actually JSON::PP in a different .pm file) bundled in the same distribution as this module."

      I was replying to OP, I thought that ‘use JSON’ would detect the availability of the XS module and use it if possible, is that correct? I am really confused about your objection to my answer. I even qualified my answer with "perhaps". Maybe you can clarify exactly what your issue with my answer is because I have no idea what the point of your reply was.

        Your reply is flawed inasmuch as OP is correct, as per the docs I quoted/linked to use JSON; does as they believe it does. Your response doesn't answer that question and muddies the waters by introducing a different module. The answer to the question you quoted is in the module documentation.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11123814]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-19 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found