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"]
Written by Pedro Tavares
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#