Using Perl to encode hash to be use by Java program. The JSON encode converts a single key to JSON array element.
my %attribute;
push (@{$attribute {"Color"}},'Green');
push (@{$attribute {"Model"}}, ('Model_1','Model_2'));
print Dumper(\%attribute);
my $json_attr = JSON->new->utf8->encode(\%attribute);
print $json_attr;
Output:
$VAR1 = {
'Model' => [
'Model_1',
'Model_2'
],
'Color' => [
'Green'
]
};
{"Model":["Model_1","Model_2"],"Color":["Green"]}
I need that the single key in the hash will look like this: {"Color":"Green"} (without the square brackets) Thanks.