Subject: | JSON clobbers UTF8 flag |
Date: | Thu, 29 Sep 2011 15:13:20 +1000 |
To: | bug-JSON [...] rt.cpan.org |
From: | Andrew Wansink <andy [...] halogix.com> |
When JSON encoding UTF8 data the resulting JSON string
does not have the UTF8 flag set. This is a problem when
concatenating the JSON with data which does have the UTF8
flag set, the original UTF8 data ends up being double encoded.
#!/usr/bin/perl
use strict;
use warnings;
use JSON;
use Encode qw/_utf8_on decode_utf8/;
use Devel::Peek;
my $foo = { 1 => decode_utf8("Müller") };
Dump($foo->{1});
my $JSON = encode_json($foo);
Dump($JSON);
my $bar = 'foo ';
utf8::upgrade($bar);
$bar .= $JSON;
Dump($bar);