Re: [Boston.pm] perl data to/from JSON?

Shlomi Fish <shlomif-l9KC3OxpiO/[email protected]> Sat, 26 Jan 2019 15:07:58 +0200
Newsgroups gmane.comp.lang.perl.perl-mongers.boston
Message-ID <[email protected]>
Hi Greg,

see https://metacpan.org/pod/JSON::MaybeXS and
https://metacpan.org/pod/Perl::Critic::Policy::Freenode::PreferredAlternatives .

Note that some of JSON's types need to be handled in care from perl code (e.g:
booleans).


On Fri, 25 Jan 2019 15:47:50 -0500 "Greg London"
<[email protected]> wrote:

> This is a work-related issue, so certain decisions are out of my control.
> Also, I know only rudimentary python, and I know absolutely nothing about
> JSON, so, this whole thing may be complete garbage for reasons I'm unaware
> of. That said:
> 
> We have a number of perl and python scripts and we are looking to share
> data between them. It was decided that we use a JSON file format to store
> data and then have all the scripts read/write this format so it wouldn't
> matter if the script was python or perl.
> 
> basically I want to do this:
> 
> my $my_complex_data = [ {key1=>data1,key2=>data2}, [ {}, {key=>[] } ]];
> use Storable qw(nstore dclone retrieve);
> nstore ($my_complex_data, 'filename');
> my $revived = retrieve('filename');
> 
> But have the intermediate file format be JSON instead of Storable's format.
> 
> We also have to go through a process to get executable modules installed,
> so if it can be pure perl, I can just copy the file to a local directory,
> check it into the project, and use it without delay.
> I can get executables installed, but they have to be approved through a
> process, and then someone has to make sure they're installed on every
> machine everywhere, including all teh machines on LSF. so executables are
> possible, but likely a bit more painful.
> 
> I looked for JSON on CPAN and found... hundreds of matches???
> 
> It looks like JSON::PP is pure perl and does what I want.
> https://metacpan.org/pod/JSON::PP
> however, it says:
> "JSON::PP is a pure perl JSON decoder/encoder, and (almost) compatible to
> much faster JSON::XS"
> 
> How compatible is "almost" compatible?
> 
> I'm not actually worried about being compatible with JSON::XS. I'm worried
> about being compatible with whatever JSON file some python script ends up
> generating, or generating a JSON file that a python script may have to
> read.
> 
> 
> JSON::XS https://metacpan.org/pod/JSON::XS says:
> "This module converts Perl data structures to JSON and vice versa. Its
> primary goal is to be correct"
> 
> How "incorrect" might JSON::PP be?
> 
> JSON::PP says it is not "java script friendly" and that "If you need
> JavaScript-friendly RFC7159-compliant pure perl module, try JSON::Tiny,"
> 
> https://metacpan.org/pod/JSON::Tiny
> 
> JSON::Tiny says "it is among the fastest pure-Perl implementations of RFC
> 7159." But it doesn't say anything about "correct"ness.
> 
> So, what's the point of JSON::PP if JSON::Tiny does everything better and
> is also pure perl?
> 
> Has anyone used any of these modules?
> 
> If I wanted to take a complex perl data structure, save it to JSON format,
> and then have a python script read that JSON file, possibly modify the
> structure, and save it back as JSON, and then my perl script open that
> JSON back up, and read it back in again, which module is most likely to be
> cross-language compatible?
> 
> Any help woudl be appreciated.
> Greg
> 
> _______________________________________________
> Boston-pm mailing list
> [email protected]
> https://mail.pm.org/mailman/listinfo/boston-pm



-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Star Trek: “We, the Living Dead” - http://shlom.in/st-wtld

Chuck Norris can only convince you that you're deceased. Summer Glau can
also convince you that you're alive, which is much harder.
    — http://www.shlomifish.org/humour/bits/facts/Summer-Glau/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

_______________________________________________
Boston-pm mailing list
[email protected]
https://mail.pm.org/mailman/listinfo/boston-pm