Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between these JSON Perl modules?

Tags:

json

perl

What's the difference between the Perl JSON modules below?

I have come across JSON::PP and JSON::XS. The documentation of JSON::PP says it is compatible with JSON::XS. What does that mean?

I am not sure what the difference between them are, let alone which of them to use. Can someone clarify?

like image 610
CJ7 Avatar asked Aug 05 '16 06:08

CJ7


1 Answers

Perl modules sometimes have different implementations. The ::PP suffix is for the Pure Perl implementation (i.e. for portability), the ::XS suffix is for the C-based implementation (i.e. for speed), and JSON is just the top-level module itself (i.e. the one you actually use).

As noted by @Quentin, this site has a good description of them. To quote:

JSON

JSON.pm is a wrapper around JSON::PP and JSON::XS - it also does a bunch of moderately crazy things for compatibility reasons, including extra shim code for very old perls [...]

JSON::PP

This is the standard pure perl implementation, and if you're not performance dependent, there's nothing wrong with using it directly [...]

JSON::XS

Ridiculously fast JSON implementation in C. Absolutely wonderful [...]

As you can see, just installing the top-level JSON module should do it for you. The part about compatibility just means that they both do the same thing, i.e. you should get the same output from both.

I installed the Perl JSON module a few years ago on a RHEL server I managed and it was a really straightforward process: just install (or build) the module from the CPAN site and you're done.

Installing should be a simple case of either using the OS package manager (if in GNU/Linux), using the cpan utility, or building from source. The OS package manager is recommended, as it helps keep things updated automatically.

To verify that it's installed, just try the following command from the terminal (assuming GNU/Linux):

$ perl -e 'use JSON;'

If it doesn't complain, then you should be good to go. If you get errors, then you should get ready to go in an adventure.

like image 140
code_dredd Avatar answered Sep 30 '22 23:09

code_dredd