From: Mischa POSLAWSKY Date: Sun, 28 Jan 2024 15:22:08 +0000 (+0100) Subject: tools/mkjson: indent objects but not arrays X-Git-Url: http://git.shiar.net/sheet.git/commitdiff_plain/9830d2491e85baa0f42cb0898f2c19974e21e96a tools/mkjson: indent objects but not arrays Pretty but not too long; assumes arrays are used as unkeyed hashes. --- diff --git a/tools/mkjson b/tools/mkjson index 6a7d948..dace34a 100755 --- 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;