unfortunately° are - like already said - decode_json and encode_json defaulting to utf8-encoded octet-streams

you need to use the object interface

use v5.12; use warnings; use Devel::Peek; use Data::Dump qw/pp/; use JSON::XS; use utf8; my $str = "\x{feff}" . '["whät","över"]'; # Internal Unicode b/c of use +utf8 Dump($str); # hence shows UTF8 flag $str =~ s/^\x{feff}//; # strip BOM by Unicode code-po +int Dump($str); # shows UTF8 flag my $JSON = JSON::XS->new; # coder for all unicode in/out my $data = $JSON->decode($str); warn pp '$data: ', $data; # ["wh\xE4t", "\xF6ver"] # NB: \xE4, \xF6 correct codep +oints for umlauts # even if each character neede +d 2 bytes my $str2 = $JSON->encode($data); # roundtrip Dump($str2); # shows UTF8 flag warn '$str eq $str2: ', $str eq $str2; # same

SV = PV(0x6bcea8) at 0x26485f0 REFCNT = 1 FLAGS = (POK,pPOK,UTF8) PV = 0x28229e8 "\357\273\277[\"wh\303\244t\",\"\303\266ver\"]"\0 [UT +F8 "\x{feff}["wh\x{e4}t","\x{f6}ver"]"] CUR = 20 LEN = 22 SV = PV(0x6bcea8) at 0x26485f0 REFCNT = 1 FLAGS = (POK,pPOK,UTF8) PV = 0x28227e8 "[\"wh\303\244t\",\"\303\266ver\"]"\0 [UTF8 "["wh\x{e +4}t","\x{f6}ver"]"] CUR = 17 LEN = 24 ("\$data: ", ["wh\xE4t", "\xF6ver"]) at d:/perl/pm/t_devel_peek.pl lin +e 21. SV = PV(0x6bd158) at 0x27482a0 REFCNT = 1 FLAGS = (POK,pPOK,UTF8) PV = 0x281d9c8 "[\"wh\303\244t\",\"\303\266ver\"]"\0 [UTF8 "["wh\x{e +4}t","\x{f6}ver"]"] CUR = 17 LEN = 66 $str eq $str2: 1 at d:/perl/pm/t_devel_peek.pl line 28.

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

°) or fortunately? depends on the perspective


In reply to Re^11: Rogue character(s) at start of JSON file (BOM; dumping references) by LanX
in thread Rogue character(s) at start of JSON file by Bod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.