File::JSON::Slurper - slurp a JSON file into a data structure, and the reverse
use File::JSON::Slurper qw/ read_json write_json /; my $ref = read_json('stuff.json'); my $data = { name => 'NEILB', age => 21 }; write_json('fibber.json', $data);
This module provides two functions for getting Perl data structures into and out of files in JSON format. One will read a Perl data structure from a JSON file, and the other will take a Perl data structure and write it to a file as JSON.
I wrote this module because I kept finding myself using File::Slurper to read JSON from a file, and then JSON::MaybeXS to convert the JSON to a Perl data structure.
No functions are exported by default, you must specify which function(s) you want to import.
Read JSON from $filename as UTF-8 and convert it to a Perl data structure. You'll get back either an arrayref or a hashref.
$filename
Takes a Perl data structure $ref, converts it to JSON and then writes it to file $filename as UTF-8.
$ref
JSON::Parse provides a function "json_file_to_perl" in JSON::Parse which is like the read_json function provided by this module. But you can't specify an encoding, and it doesn't provide a function for writing to a file as JSON.
read_json
File::Slurper is used to read and write files.
JSON::MaybeXS is used to encode and decode JSON. This itself is a front-end to the various JSON modules available on CPAN.
https://github.com/neilb/File-JSON-Slurper
Neil Bowers <neilb@cpan.org>
This software is copyright (c) 2016 by Neil Bowers <neilb@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install File::JSON::Slurper, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::JSON::Slurper
CPAN shell
perl -MCPAN -e shell install File::JSON::Slurper
For more information on module installation, please visit the detailed CPAN module installation guide.