Yes indeed it should be UTF-8 but we've already established that the file has "strange" (being polite) encoding...

$| = 1; $/ = undef; print "Reading JSON file"; open my $fh, '<:encoding(UTF-8)', '../data/publicextract.charity.json' + or die "Unable to read Charity JSON File"; my $data = <$fh>; close $fh; print "...done\n"; $data =~ s/^\x{feff}//; # Strip off BOM print "Decoding JSON file"; my $js = decode_json $data; # line 24 print "...done\n";

This takes about 10 minutes to read the 462Mb JSON file then fails with Decoding JSON fileWide character in subroutine entry at import.pl line 24

Given the time taken to open the file in UTF-8 and the error, I am thinking there is some nasty encoding hidden somewhere in this file

UPDATE

Changing the encoding like so

print "Reading JSON file"; open my $fh, '<', '../data/publicextract.charity.json' or die "Unable +to read Charity JSON File"; my $data = <$fh>; close $fh; print "...done\n"; $data =~ s/^\357\273\277//; # Strip off BOM
takes about 5 minutes to open the file but gives the strange error Decoding JSON fileKilled

"Strange" because the error doesn't include at import.pl line 24!

Another UPDATE

It seems I might be running out of memory...380400 records in the JSON file seems to be too much...


In reply to Re^10: Rogue character(s) at start of JSON file (BOM; dumping references) by Bod
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.