Encode a String to UTF-8 in Perl
12:37 09 Aug 2020

The utf8 library could not convert my data to utf-8.

#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use JSON;

my $data = qq( { "cat" : "Büster" } );
$data= utf8::encode($data);
$data= JSON::decode_json($data);
print $data->{"cat"};

OUTPUT:

malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)")

I do not want to use Unicode::UTF8 or Encode. I want to solve this problem using utf8 library.

perl utf-8