Catman...::JSON(3pm)

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

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

okay bestie, so this is the manual page for Catman...::JSON, section 3pm β€” and the actual star of the show, the module itself, is Catmandu::Exporter::JSON. yes the page name and the module name are doing two different things, we love that for them, no notes. it's giving "user contributed perl documentation" energy and honestly? iconic. πŸŽ€


✨ NAME ✨

Catmandu::Exporter::JSON β€” a JSON exporter. that's it, that's the whole name section, she's concise πŸ’…


🌸 SYNOPSIS 🌸

okay so here's how you actually use her. three ways, all valid, all slay:

# From the command line

catmandu convert YAML to JSON --pretty 1 < input.yml

# Export in the line-delimited format

catmandu convert YAML to JSON --line_delimited 1 < input.yml

# In a Perl script

use Catmandu;

my $exporter = Catmandu->exporter('JSON', fix => 'myfix.txt');

$exporter->add_many($arrayref);
$exporter->add_many($iterator);
$exporter->add_many(sub { });

$exporter->add($hashref);

printf "exported %d items\n" , $exporter->count;

like, add_many takes an arrayref, an iterator, or even a bare sub { } 🫢 and then you can flex with a little printf counting your items at the end. main character behaviour fr fr.


πŸ¦‹ DESCRIPTION πŸ¦‹

so basically: this Catmandu::Exporter exports your items serialized in JSON format. that's the vibe. πŸ’–

and by default? every single item gets printed condensed onto one line. no sprawl, no drama, just tight little lines. periodt.


πŸŽ€ CONFIGURATION πŸŽ€

here come the knobs and dials bestie, read carefully, there's a lot of them but they're all gonna eat:

  • file β€” write your output to a local file, given by its path or a file handle. OR, plot twist, you can pass a scalar reference to write into a string, or a code reference to write into a callback function. three doors, pick your fave πŸšͺ✨
  • fh β€” write the output to an IO::Handle. if you don't specify one, Catmandu::Util::io steps in and creates the output handle from the file argument, or just falls back to using STDOUT. she's resourceful πŸ’…
  • fix β€” an ARRAY of one or more fixes or file scripts that get applied to your exported items. glow-up your data on the way out, we love a transformation arc 🧚
  • encoding β€” the binmode of the output stream fh. defaults to ":utf8". keep it cute, keep it utf8 πŸ’œ
  • pretty β€” pretty-print that JSON. make it look good for the timeline ✨
  • indent, space_before, space_after, canonical β€” these are your JSON serialization options. the formatting squad, all four of them, grouped together, doing their little formatting things πŸŽ€
  • array β€” structure the data as a JSON array. default is 1. so yeah, array mode is the factory setting πŸ‘‘
  • line_delimited β€” export items as newline delimited JSON. default is 0.
⚠️ okay important bestie, listen: if line_delimited is 1, then array, pretty, indent, space_before and space_after all get ignored. like, completely. they're standing outside the club. so don't come for me when your pretty does nothing, i warned you 😭

🌈 SEE ALSO 🌈

  • Catmandu::Exporter::YAML β€” the sibling, the other format, the parallel universe version of this whole situation πŸ¦‹

and that's the whole page bestie!! this gem is perl v5.40.1 and this documentation is dated 2026-01-24. mwah, go export something gorgeous πŸ’–πŸ’…βœ¨

πŸ“¦ where this page comes from