Skip to content

Instantly share code, notes, and snippets.

@nichtich
Created January 17, 2011 22:49
Show Gist options
  • Save nichtich/783645 to your computer and use it in GitHub Desktop.
Save nichtich/783645 to your computer and use it in GitHub Desktop.
Wandelt PICA+ (egal welche Form) nach JSON (ohne Subfield-Ordnung)
#!/usr/bin/perl
use strict;
use warnings;
=head1 NAME
pica2json - Wandelt PICA+ (egal welche Form) nach JSON (ohne Subfield-Ordnung)
=cut
use PICA::Parser qw(parsefile);
use JSON;
my ($in,$out) = (\*STDIN, *STDOUT);
my $json = { };
parsefile( $in, Field => \&handle_field );
binmode $out, ':utf8';
print $out JSON->new->pretty->encode($json);
sub handle_field {
my $field = shift;
my $subfields = { };
foreach my $sf ( $field->content ) {
my ($code,$value) = @$sf;
push @{ $subfields->{ $code } }, $value;
}
push @{ $json->{ $field->tag } }, $subfields;
undef;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment