use v5.12; use warnings; use Devel::Peek; use Data::Dump qw/pp/; use JSON::XS; use utf8; my $str = "\x{feff}" . '["whät","över"]'; # Internal Unicode b/c of use utf8 Dump($str); # hence shows UTF8 flag $str =~ s/^\x{feff}//; # strip BOM by Unicode code-point Dump($str); # shows UTF8 flag my $JSON = JSON::XS->new; # coder for all unicode in/out my $data = $JSON->decode($str); warn pp '$data: ', $data; # ["wh\xE4t", "\xF6ver"] # NB: \xE4, \xF6 correct codepoints for umlauts # even if each character needed 2 bytes my $str2 = $JSON->encode($data); # roundtrip Dump($str2); # shows UTF8 flag warn '$str eq $str2: ', $str eq $str2; # same