title: Parsing utf-8 json with Perl
body: <p>I'm trying to parse an utf-8 json file in Perl.
  <a href="https://jsonlint.com/" rel="nofollow noreferrer">https://jsonlint.com/</a> says the json is valid.
  Still I get the error message:</p>
  
  <blockquote>
    <p>malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "\x{ef}\x{bb}\x{bf}{"...") at parse.pl line 15.</p>
  </blockquote>
  
  <p>The code is:</p>
  
  <pre><code>use strict;
  use utf8;
  use JSON qw( );
  
  my $filename = 'k2.json';
  
  my $json_text = do {
     open(my $json_fh, $filename) or die("Can't open $filename: $!\n");
     local $/;
     &lt;$json_fh&gt;
  };
  
  my $json = JSON-&gt;new;
  my $data = $json-&gt;decode($json_text);
  
  for ( @{$data-&gt;{data}} ) {
     print $_-&gt;{lng}."\n";
  }
  </code></pre>
  
  <p>The utf-8 coded json is:</p>
  
  <pre><code>{"data":
  [{"lng":"19.03252602",
  "lat":"47.49795914",
  "display_name":"I. kerület (Attila út)",
  "active":"1",
  "url":"/hu/kormanyablakok/budapest/i-kerulet/i-kerulet-attila-ut/283"
  }]
  }
  </code></pre>
  
  <p>I see that (ef, bb, bf) are the three bytes that indicate that it's an utf-8 document, so I don't understand what JSON package is missing here. How can I make it work?<br>
  Specifying <b>"&lt;:encoding(UTF-8)"</b> at opening the file did not help either...</p>