I have a feeling that Dumper shouldn’t actually produce ambiguous output, so escaped something is what we should expect from it.
So unless I did something horribly wrong, this is the input (sprinkled with a Unicode character outside Latin-1 range for the sake of example; converted to a UTF-8 encoded byte stream for JSON), the input parsed as JSON, printed to STDOUT on a UTF-8 terminal with your lines added.
The output:use Data::Dumper; use Encode qw(encode); use JSON; use utf8; use open ":std", ":encoding(UTF-8)"; #use open ":std", ":locale"; ## totally didn't do anything for me my $j = qq/{ "Particípio passadő": 1 }/; my $jp = JSON->new->utf8; my $d = $jp->decode(encode("UTF-8", $j)); print "$j\n"; print Dumper($d); print Dumper($j); print Dumper(encode("UTF-8", $j));
{ "Particípio passadő": 1 }
$VAR1 = {
"Partic\x{ed}pio passad\x{151}" => 1
};
$VAR1 = "{ \"Partic\x{ed}pio passad\x{151}\": 1 }";
$VAR1 = '{ "ParticÃpio passadÅ": 1 }';
According to the manual, evaling the Dumper output should give us back the original data, so the escaped wide characters in the string seem right to me. Peculiar is how, when given a UTF-8 byte stream, it will not escape things and dump something awkward instead (last line). With $Data::Dumper::Useqq set it produces a better-looking string:
$VAR1 = "{ \"Partic\303\255pio passad\305\221\": 1 }";
In reply to Re^2: JSON, Data::Dumper and accented chars in utf-8
by Ralesk
in thread JSON, Data::Dumper and accented chars in utf-8
by silentius
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |