NAME
File::JSON::Slurper - slurp a JSON file into a data structure, and the reverse
SYNOPSIS
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);
DESCRIPTION
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.
FUNCTIONS
read_json($filename)
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.
write_json($filename, $ref)
Takes a Perl data structure $ref
, converts it to JSON and then writes it to file $filename
as UTF-8.
SEE ALSO
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.
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.
REPOSITORY
https://github.com/neilb/File-JSON-Slurper
AUTHOR
Neil Bowers <neilb@cpan.org>
COPYRIGHT AND LICENSE
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.