Created
August 4, 2012 21:17
-
-
Save benr75/3260023 to your computer and use it in GitHub Desktop.
Display JSON nicely from the command line using ruby
This file contains 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
#!/usr/bin/env ruby | |
# Example usage: | |
# curl https://api.twitter.com/1/statuses/show.json?id=231426135903305728 | jv.rb | |
# | |
require 'rubygems' | |
require 'awesome_print' | |
require 'json' | |
ap JSON.parse(ARGF.read) | |
# Was going to write to a file and open the file, but awesome_print line breaks didn't get written to file | |
=begin | |
filename = "#{ENV['HOME']}/tmp/#{rand(100000)}.json" | |
File.open(filename, 'w') {|f| f.write(ap JSON.parse(ARGF.read)) } | |
`open #{filename}` | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice, that's all I was hoping you did :)