MARC::...rd::MiJ(3pm)

πŸ“¦
version 0.04 Β· 4 versions
, in debian bookworm, ubuntu noble

πŸ’– MARC::Record::MiJ πŸ’–

okay bestie, so this is the manual page for MARC::Record::MiJ, living in the User Contributed Perl Documentation section, and it's giving "3pm" the whole way through. It's a Perl module for flipping MARC::Record objects back and forth to and from marc-in-json structures. Yes. Both directions. Iconic behaviour honestly.


✨ NAME ✨

MARC::Record::MiJ β€” Convert MARC::Record to/from marc-in-json structure πŸ¦‹


✨ VERSION ✨

Version 0.04 πŸ’…


✨ SYNOPSIS ✨

no thoughts, just code, bestie:

  use MARC::Record;
  use MARC::Record::MIJ

  my $str = get_marc_in_json_from_somewhere;

  # The most common use will be to use methods monkeypatched into MARC::Record
  my $r = MARC::Record->new_from_mij($str);
  my $json = $r->to_mij;

  # You can also work with the underlying hash/array structure if you're dealing with
  # json serialization/deserialization on your own

  my $mij_structure = $r->to_mij_structure;
  my $r = MARC::Record->new_from_mij_structure($mij_structure);

  # You can also call things on MARC::Record::MiJ

  my $r = MARC::Record::MiJ->new($str);
  my $json = MARC::Record::MiJ->to_mij($r);
  my $mij_structure = MARC::Record::MiJ->to_mij_structure($r);
  my $r = MARC::Record::MiJ->new_from_mij_structure($mij_structure);

✨ DESCRIPTION ✨

So the whole vibe here: this module reads and writes MARC-in-JSON structures and strings, the kind that pymarc / ruby-marc / marc4j support, and it's the flavour described over at http://dilettantes.code4lib.org/blog/2010/09/a-proposal-to-serialize-marc-in-json/ 🌸

Genuinely do NOT confuse this with another, incompatible JSON encoding that lives in the module MARC::File::JSON β€” which, as far as the author knows, isn't supported by other readers/writers. Different girl entirely. πŸ’€

For reading, you probably don't need to touch this directly, fr fr β€” go peek at MARC::File::MiJ instead, which reads newline-delimited marc-in-json files either all by itself or in cahoots with MARC::Batch 🫢

And lowkey, the MARC::Record distribution doesn't really do the whole writing out files thing. But you can absolutely do something like this:

    # convert file from marc binary to marc-in-json
    use MARC::Batch;
    use MARC::Record::MiJ;
    my $batch = MARC::Batch->new('USMARC', 'file.mrc');
    open(my $jsonfile, '>', 'file.ndj' );
    while (my $r = $batch->next) {
      print $jsonfile MARC::Record::MiJ->to_mij($r), "\n";
    }
    close $jsonfile;

…and boom, you've turned a binary file into newline-delimited marc-in-json. main character energy, truly ✨


✨ SUBROUTINES/METHODS ✨

json

Get a json object to work with β€” it's memoized, so it's remembered for you πŸŽ€ The whole point of controlling it ourselves is making sure it's not doing anything pretty (like, say, putting newlines in β€” which would make producing a newline-delimited json file way harder than it needs to be).

new($str)

Take a JSON string and turn it into a MARC::Record object πŸ’–

to_mij($r)

Take a record; return a JSON string 🌈

MARC::Record::JSON->to_mij_structure($r)

Turn a record into a marc-in-json compatible hash; hand you back the hash pointer πŸ’«

controlfield_to_mij_structure($field)

Turn a MARC::Record controlfield into an appropriate hash πŸ¦‹

valuefield_to_mij_structure($field)

Turn a MARC::Record valuefield into an appropriate hash 🌸

subfield_to_mij_structure($sf)

Turn a MARC::Record subfield pair (that's an arrayref duple of code/value, iykyk) into an appropriate hash ⭐

my $r = MARC::Record::JSON->new_from_mij_structure($mij_structure)

Given a marc-in-json structure, return a MARC::Record object πŸ’œ

new_field_from_mij_structure($f)

Given a field structure, create an appropriate field β€” control or variable, your choice bestie πŸŽ€

new_datafield_from_mij_structure

Support for new_field_from_mij_structure; this one does the more complex work of actually creating a datafield πŸ‘‘


✨ Monkeypatching MARC::Record ✨

This adds new_from_mij_structure($mij_structure) and to_mij_structure() to MARC::Record πŸ’βœ¨

  my $r = MARC::Record->new_from_mij_structure($mij_structure);
  $mij_structure = $r->to_mij_structure;

✨ AUTHOR ✨

Bill Dueber, "<dueberb at umich.edu>" πŸ’–


✨ BUGS ✨

Please report any bugs or feature requests to "bug-MARC-File-MiJ at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MARC-File-MiJ>. The author gets notified, and then you automatically get notified of progress on your bug as changes get made 🫢 no ghosting here.


✨ SUPPORT ✨

You can find documentation for this module with the perldoc command πŸŽ€

    perldoc MARC::Record::MiJ

You can also look for information at:

  • RT: CPAN's request tracker (report bugs here)

<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MARC-File-MiJ>

  • AnnoCPAN: Annotated CPAN documentation

<http://annocpan.org/dist/MARC-File-MiJ>

  • CPAN Ratings

<http://cpanratings.perl.org/d/MARC-File-MiJ>

  • Search CPAN

<http://search.cpan.org/dist/MARC-File-MiJ/>


✨ ACKNOWLEDGEMENTS ✨

(yeah bestie, this section is literally empty in the original β€” not me being lazy, I promise πŸ™ˆ)


Copyright 2013 Bill Dueber.

This software is free software and may be distributed under the same terms as Perl itself. πŸ’…


and that's the whole page, bestie πŸŽ€ signed off from perl v5.34.0, dated 2022-06-15, filed under MARC::...rd::MiJ(3pm) in the User Contributed Perl Documentation. go forth and serialize βœ¨πŸ¦‹πŸ’–

πŸ“¦ where this page comes from