Skip to content

Instantly share code, notes, and snippets.

@DeMarko
Created October 15, 2010 16:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeMarko/628446 to your computer and use it in GitHub Desktop.
Save DeMarko/628446 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# == Synopsis
# jsonpretty: a quick script for making JSON output legible
#
# == Usage
# jsonpretty [a JSON encoded file]
# [some stream with JSON text] | jsonpretty
#
# For this help use: jsonpretty -h
#
# == Author
# Dannel Jurado
#
# == Fun Fact
# the RDoc for this script is longer than the script itself
# even without this fact!
require "rubygems"
require "json"
require "yaml"
require "optparse"
require "rdoc/usage"
opts = OptionParser.new
opts.on('-h', '--help') { RDoc::usage() }
opts.parse!(ARGV)
jsonfile = ARGV[0].nil? ? $< : File.open(ARGV[0])
puts YAML.dump(JSON.parse(jsonfile.readlines.join))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment