Posted By

vestimir on 12/07/11


Tagged

parse rails ruby web json


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

darkhawk
litvil


Fetch remote JSON in Ruby


 / Published in: Ruby
 

An example method for fetching remote JSON data in Ruby.

  1. require 'rubygems'
  2. require 'json'
  3. require 'net/http'
  4.  
  5. def fetch(url)
  6. resp = Net::HTTP.get_response(URI.parse(url))
  7. data = resp.body
  8. JSON.parse(data)
  9. end
  10.  
  11. puts fetch "http://example.org/sample.json"

Report this snippet  

You need to login to post a comment.