1
0
mirror of https://github.com/meineerde/dotfiles.git synced 2026-02-06 00:53:23 +00:00

Pretty print JSON

This commit is contained in:
Holger Just 2013-09-23 16:24:01 +02:00
parent 644772b6e7
commit e664bba35e

23
bin/json Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env ruby
require 'rubygems' # 1.8.7
require 'json'
if STDIN.tty?
if File.exist?("/usr/bin/pbpaste")
data = IO.popen('/usr/bin/pbpaste', 'r+').read
else
$stderr.puts 'your_command | json [--color]'
exit 1
end
else
data = STDIN.read
end
json = JSON.parse(data)
if ARGV.include?('--color')
require 'ap'
ap json
else
puts JSON.pretty_generate(json)
end