Catman...::JSON(3pm)

πŸ“¦
version 1.2025 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– Catman...::JSON(3pm) πŸ’–

okay bestie, gather round 🫢 this is a page from the User Contributed Perl Documentation set, and it's all about Catmandu::Importer::JSON β€” yes the manpage header is literally Catman...::JSON(3pm), we don't make the rules, we just slay within them ✨


🌸 NAME 🌸

Catmandu::Importer::JSON β€” the package that imports JSON data. that's it, that's the whole job, and it does it gorgeously πŸ’…


✨ SYNOPSIS ✨

so here's how you'd actually use it. from the command line, like a main character:

# 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

and if you're in a Perl script (iykyk), it's giving:

# In a Perl script

use Catmandu;

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

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

obsessed. genuinely. πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

this package imports JSON data, no cap. and the parser? it's quite liberal in the input it accepts β€” it's not gonna gatekeep your JSON, it'll just take it 🫢

and if you want speed, you can use the line_delimited option to parse "newline delimited JSON" faster. here's the vibe:

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

one object per line, no commas, no drama. slay ✨


πŸ‘‘ CONFIGURATION πŸ‘‘

the way each of these options is literally a whole personality:

  • file β€” read input from a local file, given by its path. or, plot twist, you can pass a scalar reference instead and it'll read from a string 🌈
  • fh β€” read input from an IO::Handle. if you don't specify it, Catmandu::Util::io gets called in to create the input stream from the file argument, or by using STDIN. it's got you either way πŸ’œ
  • encoding β€” the binmode of the input stream fh. it's set to :utf8 by default, as a treat πŸŽ€
  • fix β€” an ARRAY of one or more fixes or file scripts to be applied to the imported items. glow-up your data on the way in, periodt πŸ’…
  • line_delimited β€” read line-delimited JSON line-by-line with a non-incremental parser. fast mode unlocked πŸ”₯
  • byte_buffer_size β€” how many bytes get read by each iteration of the incremental parser. ignored if line_delinmited is 1 (yes that spelling is in the original, bestie, we report what we see, no editing the source πŸ’€). default is 256.

πŸ’€ METHODS πŸ’€

every Catmandu::Importer is a Catmandu::Iterable, and all its methods are inherited. so like, you get the whole family tree 🌳

but here's the tea, and it's important tea: the methods are not idempotent. JSON streams can only be read once. read it once and it's gone, like a limited-edition drop. don't come back asking for seconds 😭


🌈 SEE ALSO 🌈

  • Catmandu::Exporter::JSON β€” the other half of the love story 🫢

and that's the whole page, bestie!! πŸ’– this was Catman...::JSON(3pm) from the User Contributed Perl Documentation, living in perl v5.40.1 and dated 2026-01-24. go import some JSON, you absolute icon πŸ‘‘βœ¨

πŸ“¦ where this page comes from