MARC::Record::MiJ(3pm) | User Contributed Perl Documentation | MARC::Record::MiJ(3pm) |
MARC::Record::MiJ - Convert MARC::Record to/from marc-in-json structure
Version 0.04
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);
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.
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).
Take a JSON string and turn it into a MARC::Record object
Take a record; return a JSON string
Turn a record into a marc-in-json compatible hash; return the hash pointer
Turn a MARC::Record controlfield into an appropriate hash
Turn a MARC::Record valuefield into an appropriate hash
Turn a MARC::Record subfield pair (arrayref duple of code/value) into an appropriate hash
Given a marc-in-json structure, return a MARC::Record object
Given a field structure, create an appropriate (control or variable) field
Support for new_field_from_mij_structure; do the more complex work of creating a datafield
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;
Bill Dueber, "<dueberb at umich.edu>"
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.
You can find documentation for this module with the perldoc command.
perldoc MARC::Record::MiJ
You can also look for information at:
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MARC-File-MiJ>
<http://annocpan.org/dist/MARC-File-MiJ>
<http://cpanratings.perl.org/d/MARC-File-MiJ>
<http://search.cpan.org/dist/MARC-File-MiJ/>
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 |