Skip to content

Instantly share code, notes, and snippets.

@dmmfll
Created February 23, 2017 17:10
Show Gist options
  • Save dmmfll/126b4ec98557bc0bd267641b6edbed96 to your computer and use it in GitHub Desktop.
Save dmmfll/126b4ec98557bc0bd267641b6edbed96 to your computer and use it in GitHub Desktop.
gist_url
auto_gistup
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# require the builtin gem
require 'json'
# create some fake data: an array of hashes
data = 10.times.each_with_index.map do |i|
{20.times.map do
("a".."z").to_a.sample
end.join => i}
end
# turn data into json string which is the same thing a lot of API's will return
# in an HTTP response body
json_data = data.to_json
p json_data.class
# undo the process
# this is what you do with the JSON string returned in
# the body of an HTTP response
converted_data = JSON.parse(json_data)
p converted_data
p converted_data.class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment