Skip to content

Instantly share code, notes, and snippets.

@benr75
Created May 24, 2013 21:47
Show Gist options
  • Save benr75/5646723 to your computer and use it in GitHub Desktop.
Save benr75/5646723 to your computer and use it in GitHub Desktop.
JSON pretty from commandline
#!/usr/bin/env ruby
# Example usage:
# curl https://api.twitter.com/1/statuses/show.json?id=231426135903305728 | jsonviewer.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