From 46afe3e6f2df9caf7e143d7e9b10b40d14eaf984 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Sun, 4 Jan 2026 22:26:27 +0900 Subject: [PATCH 1/3] Add space(s) after commas in an array as well --- lib/JSON/PP.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/JSON/PP.pm b/lib/JSON/PP.pm index eca2897..836330c 100644 --- a/lib/JSON/PP.pm +++ b/lib/JSON/PP.pm @@ -450,7 +450,8 @@ sub allow_bigint { $self->_down_indent() if ($self->{PROPS}[P_INDENT]); return '[]' unless @res; - return '[' . $pre . join( ",$pre", @res ) . $post . ']'; + my $space = $self->{PROPS}[P_SPACE_AFTER] ? ' ' : ''; + return '[' . $pre . join( ",$space$pre", @res ) . $post . ']'; } sub _looks_like_number { From 23f714a03fd235239b99f3838c6a0f8d30c91633 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Sun, 4 Jan 2026 22:26:35 +0900 Subject: [PATCH 2/3] Add a test --- t/gh_89_space_after_comma.t | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 t/gh_89_space_after_comma.t diff --git a/t/gh_89_space_after_comma.t b/t/gh_89_space_after_comma.t new file mode 100644 index 0000000..fd3a48a --- /dev/null +++ b/t/gh_89_space_after_comma.t @@ -0,0 +1,15 @@ +use strict; +use warnings; +use Test::More; + +BEGIN { $ENV{PERL_JSON_BACKEND} = 0; } + +my @candidates = qw(JSON::PP JSON::XS Cpanel::JSON::XS); + +for my $json_module (@candidates) { + eval "require $json_module; 1" or next; + my $got = $json_module->new->utf8->space_after(1)->encode({x=>[1,2]}); + is $got => qq!{"x": [1, 2]}!, "$json_module has a space after 1"; +} + +done_testing; From f26a18868f8ce638343c017a2b38260c365b2348 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Sun, 4 Jan 2026 22:39:30 +0900 Subject: [PATCH 3/3] Only add spaces if nothing else will be added --- lib/JSON/PP.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/JSON/PP.pm b/lib/JSON/PP.pm index 836330c..c910561 100644 --- a/lib/JSON/PP.pm +++ b/lib/JSON/PP.pm @@ -450,7 +450,7 @@ sub allow_bigint { $self->_down_indent() if ($self->{PROPS}[P_INDENT]); return '[]' unless @res; - my $space = $self->{PROPS}[P_SPACE_AFTER] ? ' ' : ''; + my $space = $pre eq '' && $self->{PROPS}[P_SPACE_AFTER] ? ' ' : ''; return '[' . $pre . join( ",$space$pre", @res ) . $post . ']'; }