package PICA::Parser::JSON;
use v5.14.1;
our $VERSION = '2.12';
use JSON::PP;
our $JSON = JSON::PP->new;
use parent 'PICA::Parser::Base';
sub _next_record {
my ($self) = @_;
if (my $line
= $self->{reader}->getline) {
my $record = $JSON->decode($line);
$record = $record->{record} if ref $record eq 'HASH';
return $record;
# TODO: cleanup occurrence and
}
}
1;
__END__
=head1 NAME
PICA::Parser::JSON - PICA JSON parser
=head2 DESCRIPTION
This parser parses L<PICA JSON|http://format.gbv.de/pica/json> format. The
current implementation expects re
package PICA::Writer::JSON;
use v5.14.1;
our $VERSION = '2.12';
use Scalar::Util qw(reftype);
use JSON::PP;
use PICA::Data;
use parent 'PICA::Writer::Base';
sub write_record {
my ($self, $reco
rd) = @_;
my $json = $self->{json};
unless ($json) {
$json = JSON::PP->new(%$self);
$json->$_($self->{$_})
for grep {exists $self->{$_}}
qw(pretty asci
f->{json} = $json;
}
print {$self->{fh}} $json->encode(PICA::Data::TO_JSON($record));
print {$self->{fh}} "\n" unless $json->get_indent;
}
1;
__END__
=head1 NAME
PICA::Writer::JSON - P
rt;
use PICA::Parser::Binary;
use PICA::Parser::PPXML;
use PICA::Parser::PIXML;
use PICA::Parser::JSON;
use PICA::Writer::XML;
use PICA::Writer::Plus;
use PICA::Writer::Plain;
use PICA::Writer::Patch;
rt;
use PICA::Writer::Binary;
use PICA::Writer::PPXML;
use PICA::Writer::PIXML;
use PICA::Writer::JSON;
use PICA::Writer::Generic;
sub pica_parser {
_pica_module('PICA::Parser', @_);
}
sub pica_
$//),
'Binary' => ($pica =~ tr/\x{1F}//),
'XML' => ($pica =~ tr/<//),
'JSON' => ($pica =~ tr/[{[]//),
'NL' => ($pica =~ tr/[\r\n]//),
'IS3' => ($pic
>{$_}{required};
}
$self->{records}++;
}
sub schema {
my $schema = dclone($_[0]->TO_JSON);
my $fields = $schema->{fields};
delete $fields->{$_} for grep {!$fields->{$_}{total}}
cc" : $tag;
}
sub TO_JSON {
my ($self) = @_;
return {map {$_ => $self->{$_}} keys %$self};
}
sub abbreviated {
my ($self) = @_;
my $abbr = dclone($self->TO_JSON);
delete $abbr->{
:Parser::Import>
=item L<PICA::Parser::XML>
=item L<PICA::Parser::PPXML>
=item L<PICA::Parser::JSON>
=item L<PICA::Parser::Patch>
=back
=head2 CONFIGURATION
=over
=item strict
By default faul
Builder;
use Getopt::Long qw(:config bundling);
use Pod::Usage;
use Scalar::Util qw(reftype);
use JSON::PP;
use List::Util qw(any all);
use Text::Abbrev;
use Term::ANSIColor;
my %TYPES = (
bin
=> 'Plus',
xml => 'XML',
ppxml => 'PPXML',
pixml => 'PIXML',
json => 'JSON',
ndjson => 'JSON',
patch => 'Patch',
);
my %COLORS = (
tag => 'magenta',
occ
($command eq 'diff') {
# only Plain and JSON support annotations
$opt->{to} = 'plain' unless $TYPES{lc $opt->{to}} eq 'JSON';
}
}
$opt->{input} = @argv ? \@ar
A::Writer::Plus>
=item L<PICA::Writer::XML>
=item L<PICA::Writer::PPXML>
=item L<PICA::Writer::JSON>
=item L<PICA::Writer::Generic>
=item L<PICA::Writer::Patch>
=back
=head1 METHODS
=head2 new
ined first {$a->[$_] ne $b->[$_]} 0 .. $#{$b});
}
sub clone {
bless TO_JSON($_[0]), 'PICA::Data::Field';
}
sub TO_JSON {
[@{$_[0]}];
}
1;
=head1 NAME
PICA::Data::Field - PICA+ Field
=hea