Created
August 24, 2015 21:22
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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