diff --git a/lib/JSON/PP.pm b/lib/JSON/PP.pm index eca2897..c910561 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 = $pre eq '' && $self->{PROPS}[P_SPACE_AFTER] ? ' ' : ''; + return '[' . $pre . join( ",$space$pre", @res ) . $post . ']'; } sub _looks_like_number { 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;