git.shiar.nl
/
sheet.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
e6b1064
)
tools/mkjson: indent objects but not arrays
author
Mischa POSLAWSKY
<perl@shiar.org>
Sun, 28 Jan 2024 15:22:08 +0000
(16:22 +0100)
committer
Mischa POSLAWSKY
<perl@shiar.org>
Sun, 25 Feb 2024 15:03:30 +0000
(16:03 +0100)
Pretty but not too long; assumes arrays are used as unkeyed hashes.
tools/mkjson
patch
|
blob
|
history
diff --git
a/tools/mkjson
b/tools/mkjson
index 6a7d9489a46bcd75fe59e1a2f1b6fab531c547fc..dace34afce91d2f6ca610c2d82b10bd6d039f65b 100755
(executable)
--- a/
tools/mkjson
+++ b/
tools/mkjson
@@
-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;