#!/usr/bin/env perl use strict; use warnings; use HTML::Entities; use Encode; use JSON::MaybeXS; my $original_string = "Eötvös Loránd University"; my $converted_string = encode_utf8( decode_entities($original_string) ); print "Original string: [$original_string]\n"; # shows the entities print "Converted string: [$converted_string]\n"; # shows the special characters my $entities_json = '{"school":"Eötvös Loránd University"}'; my $converted_json = encode_utf8(decode_entities($entities_json)); print "Original JSON: [$entities_json]\n"; # shows the entities print "Converted JSON: [$converted_json]\n"; # looks right: shows the special characters my $decoded_json = decode_json($converted_json); print "School: " . $decoded_json->{'school'} . "\n"; # should be "Eötvös Loránd University" but is actually "�tv�s Lor�nd University", with the special characters messed up (N.B. Perlmonks is showing this incorrectly as well)