I have this JSON string
$json_string = qq{{"error" : "User $user doesn't exist."}};
which I build on a low level, so to speak.
How to encode it using the JSON module?
Right now i am encoding hashes like this
use JSON;
my $json_string;
my $json = JSON->new;
$json = $json->utf8;
my $data;
$data->{users} = $json->encode(\%user_result);
$data->{owners} = $json->encode(\%owner_result);
$json_string = to_json($data);
print $cgi->header(-type => "application/json", -charset => "utf-8");
print $json_string;
source
share