Skip to content

Instantly share code, notes, and snippets.

@paul
Created July 15, 2012 22:19
Show Gist options
  • Save paul/3118895 to your computer and use it in GitHub Desktop.
Save paul/3118895 to your computer and use it in GitHub Desktop.
A better pretty_json.rb

Installation

  1. Copy prissy to ~/bin (or elsewhere in your $PATH)
  2. chmod +x prissy
  3. gem install awesome_print multi_json

Usage

$ some_command_that_outputs_json | prissy

Example

Example Output

#!/usr/bin/env ruby
begin
require 'awesome_print'
require 'multi_json'
rescue LoadError
warn "prissy needs the `awesome_print` and `multi_json` gems available to do its job"
puts STDIN.read
raise
end
opts = {
:indent => 2,
:index => false,
:sort_keys => true
}
begin
ap MultiJson.decode(STDIN), opts
rescue
warn "this doesn't look like JSON..."
puts STDIN.read
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment