This simple code segment shows a problem that I am encountering with JSON :: XS encoding in Perl:
#!/usr/bin/perl use strict; use warnings; use JSON::XS; use utf8; binmode STDOUT, ":encoding(utf8)"; my (%data); $data{code} = "Gewürztraminer"; print "data{code} = " . $data{code} . "\n"; my $json_text = encode_json \%data; print $json_text . "\n";
The output of this result:
johnnyb@boogie :~/Projects/repos > ./jsontest.pl data{code} = Gewürztraminer {"code":"Gewürztraminer"}
Now, if I comment on the binmode line above, I get:
johnnyb@boogie :~/Projects/repos > ./jsontest.pl data{code} = Gew rztraminer {"code":"Gewürztraminer"}
What's going on here? Please note that I am trying to fix this behavior in a Perl CGI script where binmode cannot be used, but I always get the "" characters, as mentioned above, in the JSON stream. How do I debug this? What am I missing?
json perl cgi
Omortis
source share