Skip to content

Instantly share code, notes, and snippets.

@mkdynamic
Created December 19, 2013 08:35
Show Gist options
  • Save mkdynamic/8036196 to your computer and use it in GitHub Desktop.
Save mkdynamic/8036196 to your computer and use it in GitHub Desktop.
Pretty print JSON command.
#!/usr/bin/env ruby
require 'optparse'
require 'json'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: example.rb [options]"
opts.on("-x", "--extended", "Use awesome print") do |*|
options[:extended] = true
end
end.parse!
json = JSON.parse($stdin.read)
unless options[:extended]
jj json
else
require 'awesome_print'
ap json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment