From 9830d2491e85baa0f42cb0898f2c19974e21e96a Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sun, 28 Jan 2024 16:22:08 +0100 Subject: [PATCH] tools/mkjson: indent objects but not arrays Pretty but not too long; assumes arrays are used as unkeyed hashes. --- tools/mkjson | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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; -- 2.30.0