Skip to content

Instantly share code, notes, and snippets.

@nornagon
Created April 17, 2015 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nornagon/9c24b68bd6d3e871add3 to your computer and use it in GitHub Desktop.
Save nornagon/9c24b68bd6d3e871add3 to your computer and use it in GitHub Desktop.
irb(main):006:0> puts ({created_at: Time.now}).to_json
{"created_at":"2014-07-09T06:20:34.167-07:00"}
irb(main):007:0> puts JSON.pretty_generate({created_at: Time.now})
{
"created_at": "2015-04-16 20:36:24 -0700"
}
@johnrees
Copy link

did you find out what was causing this? I got here from http://stackoverflow.com/questions/86653/how-can-i-pretty-format-my-json-output-in-ruby-on-rails#comment47516432_23018176

>> puts ({created_at: Time.now}).to_json
{"created_at":"2016-02-25T14:25:41+00:00"}

>> puts JSON.pretty_generate({created_at: Time.now})
{
  "created_at" : "2016-02-25T14:25:42+00:00"
}

@ConorSheehan1
Copy link

@johnrees it's ActiveSupport's redefinition of to_json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment