6gcznw
Last Updated: February 25, 2016
·
728
· ordepdev
49eba23cc4b611e2bacd22000a9e08df 7

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.website.com/user/1}"
api_json_result     = JSON.parse(open(api_url).read)

puts api_json_result["any_field"]
Say Thanks
Respond