Skip to content

Instantly share code, notes, and snippets.

@markembling
Created July 13, 2011 12:56
Show Gist options
  • Save markembling/1080247 to your computer and use it in GitHub Desktop.
Save markembling/1080247 to your computer and use it in GitHub Desktop.
Date/time JSON serialisation in Ruby
irb(main):004:0> require 'json'
=> true
irb(main):005:0> data = { "timestamp" => Time.new }
=> {"timestamp"=>2011-07-13 13:55:29 +0100}
irb(main):006:0> json = data.to_json
=> "{\"timestamp\":\"2011-07-13 13:55:29 +0100\"}"
irb(main):007:0> deserialised = JSON.parse json
=> {"timestamp"=>"2011-07-13 13:55:29 +0100"}
irb(main):008:0> deserialised["timestamp"].class
=> String
irb(main):009:0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment