Skip to content

Instantly share code, notes, and snippets.

@thecristen
Created August 24, 2015 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecristen/1621bec07927ce4999f3 to your computer and use it in GitHub Desktop.
Save thecristen/1621bec07927ce4999f3 to your computer and use it in GitHub Desktop.
take a url that returns a json response and print it all pretty
require 'json'
require 'net/http'
def getPrettyJSON(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
p = JSON.parse(response.body)
return JSON.pretty_generate(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment