title: How to convert Perl objects into JSON and vice versa
body: <p>I have defined a Point object in a file <code>Point.pm</code> as following:</p>
  
  <pre><code>package Point;
  sub new {
      my ($class) = @_;
      my $self = {
          _x =&gt; 0,
          _y =&gt; 0,
      };
      return bless $self =&gt; $class;
  }
  
  sub X {
      my ($self, $x) = @_;
      $self-&gt;{_x} = $x if defined $x;
      return $self-&gt;{_x};
  }
  
  sub Y {
      my ($self, $y) = @_;
      $self-&gt;{_y} = $y if defined $y;
      return $self-&gt;{_y};
  }
  
  1;
  </code></pre>
  
  <p>Now when I use <a href="http://p3rl.org/JSON" rel="noreferrer">JSON</a> to convert the object to JSON by the following code:</p>
  
  <pre><code>use JSON;
  use Point;
  
  Point $p = new Point;
  $p-&gt;X(20);
  $p-&gt;Y(30);
  
  my $json = encode_json $p;
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>encountered object 'Point=HASH(0x40017288)', but neither allow_blessed nor convert_blessed settings are enabled at test.pl line 28
  </code></pre>
  
  <p>How do I convert to and from JSON to an object using the JSON module?</p>