binmode *STDOUT, ':encoding(UTF-8)';
Perl JSON modules keep the strings in parsed structures as characters, but when serializing to JSON strings, they use bytes and UTF-8 encoding.
Update:
According to the specification, JSON doesn't use entities, but it can use the \uXXXX notation, so instead of using HTML::Entities, you can try
sub convert { my ($s) = @_; $s =~ s/&#x([[:xdigit:]]{4});/\\u$1/gr } my $entities_json = '{"school":"Eötvös Loránd Uni +versity"}'; my $converted_json = convert($entities_json); print "Original JSON: [$entities_json]\n"; print "Converted JSON: [$converted_json]\n"; # [{"school":"E\u00F6tv\ +u00F6s Lor\u00E1nd University"}] my $decoded_json = decode_json($converted_json); binmode STDOUT, ':encoding(UTF-8)'; print "School: " . $decoded_json->{'school'} . "\n"; # Eötvös Loránd +University
In reply to Re: Converting entities in JSON context
by choroba
in thread Converting entities in JSON context
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |