tools/mkjson: indent objects but not arrays
[sheet.git] / tools / mkjson
index 6a7d9489a46bcd75fe59e1a2f1b6fab531c547fc..dace34afce91d2f6ca610c2d82b10bd6d039f65b 100755 (executable)
@@ -2,6 +2,12 @@
 use 5.012;
 use warnings;
 use JSON;
+use re '/msx';
+
+my %opt;
+my $jsonify = JSON->new->utf8->canonical;
+$jsonify->pretty if $opt{pretty};
 
 my $data = do "./$ARGV[0]" or die $@;
-print JSON->new->utf8->canonical->encode($data);
+print $jsonify->encode($data)
+       =~ s{\[ \K\n ([^][]+) (?=\])}{$1 =~ s/(?:\A|\n) \s*//gr}reg;