title: Ruby serialize struct with JSON
body: <p>I am trying to serialize a simple struct to JSON which works fine, but I can't get it to create an instance of that struct from the JSON. Here is how I am trying to do it.</p>
  
  <pre><code>require 'rubygems'
  require 'json'
  
  Person = Struct.new(:name, :age)
  
  json = Person.new('Adam', 19).to_json
  puts json
  
  me = JSON.load(json)
  puts me.name
  </code></pre>
  
  <p>And I get the following output:</p>
  
  <pre><code>"#&lt;struct Person name=\"Adam\", age=19&gt;"
  /usr/lib/ruby/1.9.1/json/common.rb:148:in `parse': 746: unexpected token at '"#&lt;struct Person name=\"Adam\", age=19&gt;"' (JSON::ParserError)
      from /usr/lib/ruby/1.9.1/json/common.rb:148:in `parse'
      from /usr/lib/ruby/1.9.1/json/common.rb:309:in `load'
      from why.rb:9:in `&lt;main&gt;'
  </code></pre>