hash ruby ke json
require 'json'
File.open("filename.json", "w") do |f|
f.write(JSON.pretty_generate(my_hash))
end
Nice Nightingale
require 'json'
File.open("filename.json", "w") do |f|
f.write(JSON.pretty_generate(my_hash))
end
response = Faraday.get('https://api.github.com/users/your_username')
r = JSON.parse(response.body, symbolize_names: true)
#OR
JSON.parse(response.body)
#'symbolize_names' turns the keys in this hash into symbols, not required
#JSON.parse is what turns the JSON object into a hash
require 'json'
my_hash = JSON.parse('{"hello": "goodbye"}')
puts my_hash["hello"] => "goodbye"