Scroll to navigation

Catmandu::Importer::JSON(3pm) User Contributed Perl Documentation Catmandu::Importer::JSON(3pm)

NAME

Catmandu::Importer::JSON - Package that imports JSON data

SYNOPSIS

    # From the command line
    
    $ catmandu convert JSON to YAML < data.json

    # or for faster newline delimited input

    $ catmandu convert JSON --line_delimited 1 to YAML < data.json

    # In a Perl script

    use Catmandu;

    my $importer = Catmandu->importer('JSON', file => "/foo/bar.json");

    my $n = $importer->each(sub {
        my $hashref = $_[0];
        # ...
    });

DESCRIPTION

This package imports JSON data. The parser is quite liberal in the input it accepts. You can use the "line_delimited" option to parse "newline delimited JSON" faster:

    { "recordno": 1, "name": "Alpha" }
    { "recordno": 2, "name": "Beta" }
    { "recordno": 3, "name": "Gamma" }

CONFIGURATION

file
Read input from a local file given by its path. Alternatively a scalar reference can be passed to read from a string.
fh
Read input from an IO::Handle. If not specified, Catmandu::Util::io is used to create the input stream from the "file" argument or by using STDIN.
encoding
Binmode of the input stream "fh". Set to ":utf8" by default.
fix
An ARRAY of one or more fixes or file scripts to be applied to imported items.
line_delimited
Read line-delimited JSON line-by-line with a non-incremental parser.
byte_buffer_size
Number of bytes that is read by each iteration of the incremental parser. Ignored if "line_delinmited" is 1. Default is 256.

METHODS

Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited. The methods are not idempotent: JSON streams can only be read once.

SEE ALSO

Catmandu::Exporter::JSON
2020-04-02 perl v5.30.0