title: How to automatically convert JSON time strings into Time objects with Ruby?
body: <p>When I’m using Ruby to consume a web service API that returns time strings in JSON, I want them automatically converted into <code>Time</code> objects (or <code>DateTime</code> objects) so that I don’t have do it manually myself.</p>
  
  <p>For example, I want this to output <code>Time</code> instead of <code>String</code>:</p>
  
  <pre><code>irb(main):001:0&gt; require 'json'
  =&gt; true
  irb(main):002:0&gt; payload = JSON.generate({ now: Time.now })
  =&gt; "{\"now\":\"2018-04-02 13:15:56 -0500\"}"
  irb(main):003:0&gt; JSON.parse(payload)['now'].class
  =&gt; String
  </code></pre>
  
  <p>I understand that times are not part of the JSON spec. I’m just wondering if there’s a way to configure Ruby’s stdlib JSON parser to automatically parse dates, or if there’s a library that does this for you.</p>