Fetch remote JSON in Ruby

/ Published in: Ruby
Save to your folder(s)

An example method for fetching remote JSON data in Ruby.

Copy this code and paste it in your HTML
  1. require 'rubygems'
  2. require 'json'
  3. require 'net/http'
  5. def fetch(url)
  6. resp = Net::HTTP.get_response(URI.parse(url))
  7. data = resp.body
  8. JSON.parse(data)
  9. end
  11. puts fetch "http://example.org/sample.json"

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.