Answers for "json to ruby hash"

-1

how to json into hash ruby

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
Posted by: Guest on October-06-2020
0

json to ruby hash

require 'json'
File.open(filename.json, w) do |f|
  f.write(JSON.pretty_generate(my_hash))
end


or

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
Posted by: Taylor Swift on April-04-2022

Browse Popular Code Answers by Language