#!/usr/bin/perl -w use 5.14.0; use utf8; use Encode; use JSON; my $json = JSON->new->utf8->pretty(); STDOUT->binmode(":utf8"); my $umbreon = "ブラッキー"; my $test = "\x{100}\x{2764}"; say "Name: $umbreon (is utf8: " . utf8::is_utf8($umbreon) . ")"; say "Test: $test (is utf8: " . utf8::is_utf8($test) . ")"; my $data = { name => $umbreon, test => $test, }; open (my $fh, ">", "utf8-test.txt"); binmode($fh, ":utf8"); print {$fh} "Name: $umbreon\nTest: $test\n"; close($fh); my $encoded = $json->encode($data); print "encoded (original): $encoded (is utf8: " . utf8::is_utf8($encoded) . ")\n"; $encoded = Encode::decode("utf-8", $encoded); print "encoded: $encoded (utf8: " . utf8::is_utf8($encoded) . ")\n"; open (my $fh2, ">", "utf8-test.json"); binmode($fh2, ":utf8"); print {$fh2} $encoded; close($fh2); __END__ [kirsle@vostro ~]$ perl utf8-test.pl Name: ブラッキー (is utf8: 1) Test: Ā❤ (is utf8: 1) encoded (original): { "test" : "€❤", "name" : "ƒ–ƒƒƒ‚ƒ" } (is utf8: ) encoded: { "test" : "Ā❤", "name" : "ブラッキー" } (utf8: 1)