Last Updated: February 25, 2016
· ordepdev

Access to JSON fields with Ruby

This little block of code can get data from any kind of JSON API service. With this we can access to any JSON field.

'open-uri' and 'json' are needed to do the job.

require 'open-uri'
require 'json'

api_url             = "h*tp://}"
api_json_result     = JSON.parse(open(api_url).read)

puts api_json_result["any_field"]