10 # imported from JSON-XS/bin/json_xs
12 my %allow_json_opt = map { $_ => 1 } qw(
13 ascii latin1 utf8 pretty indent space_before space_after relaxed canonical allow_nonref
14 allow_singlequote allow_barekey allow_bignum loose escape_slash
19 'v' => \( my $opt_verbose ),
20 'f=s' => \( my $opt_from = 'json' ),
21 't=s' => \( my $opt_to = 'json' ),
22 'json_opt=s' => \( my $json_opt = 'pretty' ),
23 'V' => \( my $version ),
24 ) or die "Usage: $0 [-v] -f from_format [-t to_format]\n";
33 $json_opt = '' if $json_opt eq '-';
35 my @json_opt = grep { $allow_json_opt{ $_ } or die "'$_' is invalid json opttion" } split/,/, $json_opt;
39 my $json = JSON::PP->new;
40 $json->$_() for @json_opt;
44 my $v = eval "no strict;\n#line 1 \"input\"\n$_";
54 my $json = JSON::PP->new;
55 $json->$_() for @json_opt;
60 Data::Dumper::Dumper($_)
67 or die "$opt_from: not a valid fromformat\n";
70 or die "$opt_from: not a valid toformat\n";
75 $_ = $F{$opt_from}->();
89 json_pp - JSON::PP command utility
93 json_pp [-v] [-f from_format] [-t to_format] [-json_opt options_to_json]
97 json_pp converts between some input and output formats (one of them is JSON).
98 This program was copied from L<json_xs> and modified.
100 The default input format is json and the default output format is json with pretty option.
108 Reads a data in the given format from STDIN.
126 Writes a data in the given format to STDOUT.
148 Acceptable options are:
150 ascii latin1 utf8 pretty indent space_before space_after relaxed canonical allow_nonref
151 allow_singlequote allow_barekey allow_bignum loose escape_slash
155 Verbose option, but currently no action in fact.
159 Prints version and exits.
164 $ perl -e'print q|{"foo":"あい","bar":1234567890000000000000000}|' |\
165 json_pp -f json -t dumper -json_opt pretty,utf8,allow_bignum
177 'foo' => "\x{3042}\x{3044}"
180 $ perl -e'print q|{"foo":"あい","bar":1234567890000000000000000}|' |\
181 json_pp -f json -t dumper -json_opt pretty
184 'bar' => '1234567890000000000000000',
185 'foo' => "\x{e3}\x{81}\x{82}\x{e3}\x{81}\x{84}"
190 L<JSON::PP>, L<json_xs>
194 Makamaka Hannyaharamitu, E<lt>makamaka[at]cpan.orgE<gt>
197 =head1 COPYRIGHT AND LICENSE
199 Copyright 2010 by Makamaka Hannyaharamitu
201 This library is free software; you can redistribute it and/or modify
202 it under the same terms as Perl itself.