charset: link symbols group in shared menu
[sheet.git] / tools / mkjson
1 #!/usr/bin/env perl
2 use 5.012;
3 use warnings;
4 use re '/msx';
5 use lib '.';
6 use JSON;
7
8 our $VERSION = '1.00';
9
10 our %get;
11 while (@ARGV) {
12         $ARGV[0] =~ s/^--// or last;  # --flag
13         my ($name, $val) = split /=/, shift, 2 or last;  # set until empty
14         $get{$name} = $val // 1;
15 }
16 my $file = shift or die "Usage: $0 [--options] <input>\n";
17
18 my $jsonify = JSON->new->utf8->canonical;
19 $jsonify->pretty if $get{pretty};
20
21 my $data = do "./$file" or die $@;
22 print $jsonify->encode($data)
23         =~ s{\[ \K\n ([^][]+) (?=\])}{$1 =~ s/(?:\A|\n) \s*//gr}reg;