MARC-Record-JSON
MARC::Record::JSON monkeypatches MARC::Record (e.g., it adds functions to MARC::Record's namespace) to allow JSON output. It requires the JSON.pm library, which in turn requires either JSON::XS (preferred; faster) or JSON::PP (pure-perl, slower).
The output format can be seen in the `samples` folder; it's a simplistic rendering, optimized for easy ready-only access. It does not allow perfect reconstruction of the underlying MARC record -- subfield order is not preserved.
To create it, just use MARC::Record and MARC::Record::JSON as you normally would and output the JSON.
my $records = MARC::File::USMARC->in('filename.mrc');
my $marc = $records->next();
print $marc->as_json_record;
### ...or, if you want to include the records in other data,
my $ds = {
searchset => $serachset,
setsize => $number_of_results,
records => []
}
while ($marc = $records->next()) {
push @{$ds->{records}}, $marc->as_json_record_structure,
}
print $json->encode($ds);
It is accompanied by a javascript file, marcjson.js, which provides a MARC::Record-ish (in a very loose sense of the suffix, '-ish'), read-only API to the data once you start working with it in javascript. It defined two function prototypes, MARCField and MARCRecord, which provide a subset of the functionality available in their perl counterparts.
You can use it as follows:
marc = new MARCRecord(JSON_from_MARC::Record::JSON);
// What's the first ISBN?
isbn = marc.subfield('020', 'a');
isbn = marc.field('020')[0].subfield('a'); // same thing
// get descriptions from the 505a's all concated together
fiveohfives = marc.dfield('505');
desc = '';
for (var i in fiveohfives) {
desc = desc + f.subfield('a');
}
Full documentation for both are inlined and available in the wiki.