Scroll to navigation

MARC::Record::MiJ(3pm) User Contributed Perl Documentation MARC::Record::MiJ(3pm)

NAME

MARC::Record::MiJ - Convert MARC::Record to/from marc-in-json structure

VERSION

Version 0.04

SYNOPSIS

  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

Reads and writes MARC-in-JSON structures and strings as supported by pymarc/ruby-marc/marc4j and described at http://dilettantes.code4lib.org/blog/2010/09/a-proposal-to-serialize-marc-in-json/

Don't confuse with another (incompatible) JSON encoding in the module "MARC::File::JSON", which to the best of my knowledge isn't supported by other readers/writers.

For reading, you probably don't need to use this directly; take a look at "MARC::File::MiJ" for reading in newline-delimited marc-in-json files by itself or in conjunction with "MARC::Batch".

The MARC::Record distribution doesn't so much do do writing out files. You can 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;

...to produce newline-delimited marc-in-json from a binary file.

SUBROUTINES/METHODS

json

Get a json object to work with (memoized). We want to control it so we make sure it's not doing anything pretty (like, say, putting newlines in, which woudl make it harder to produce newline-delimited json file).

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; return 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 (arrayref duple of code/value) 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 (control or variable) field

new_datafield_from_mij_structure

Support for new_field_from_mij_structure; do the more complex work of creating a datafield

Monkeypatching MARC::Record

Add "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>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc MARC::Record::MiJ

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2013 Bill Dueber.

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

2022-06-15 perl v5.34.0