title: How to do Ruby object serialization using JSON
body: <p>I have a structure of simple container classes like so (in pseudo ruby):</p>
  
  <pre><code>class A
    attr_reader :string_field1, :string_field2
    ...
  end
  
  class B
    attr_reader: int_field3, :string_field4
    ...
  end
  
  # C includes an instance of A and B
  class C
    attr_reader: :a_instance, :b_instance
    ...
  end
  </code></pre>
  
  <p>Is there are simple way to de/serialize this to JSON in Ruby? Or should I make nested serialization methods per class as in <a href="http://flori.github.com/json/" rel="noreferrer">this example</a>?</p>
  
  <p>EDIT:</p>
  
  <p>In my specific scenario, I want to POST some JSON data to a server running Ruby, which will extract the data and act accordingly.</p>
  
  <p>The sender of the JSON is not necessarily a Ruby process, but may be the back end of some other system. (Although it is Ruby in my test harness).</p>
  
  <p>So, I don't need the JSON to be in some "Ruby specific" format, I just assumed it would be easier if that was actually built-in to Ruby.</p>