Skip to content

Instantly share code, notes, and snippets.

@benr75
Created August 4, 2012 21:17
Show Gist options
  • Save benr75/3260023 to your computer and use it in GitHub Desktop.
Save benr75/3260023 to your computer and use it in GitHub Desktop.
Display JSON nicely from the command line using ruby
#!/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
@n3bulous
Copy link

n3bulous commented Aug 4, 2012

Nice, that's all I was hoping you did :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment