This gem is inspired by the JSON Editor Online tool. It contains a CLI for pretty formatting JSON files on your file system. It will let you bulk format files as well. It also has a Prettify::Prettifier module which you can use in your code to generated pretty JSON output. It uses the Ruby JSON gem's pretty_generate method with a minor modification to improve formatting.

Installation

Add this line to your application's Gemfile:

gem 'prettify'

And then execute:

$ bundle

Or install it yourself as:

$ gem install prettify

Usage

To use in our code:

 class MyClass
     include Prettify::Prettifier
     def pretty
        # Use a JSON string
        some_json = '{"one": 1}'
        puts prettify(some_json)

        # Or use a hash
        some_json = {"one"=> 1}
        puts prettify(some_json)
     end
  end

To use the CLI use type the command prettify.

Usage:
  prettify json -l, --location=LOCATION

Options:
   -l, --location=LOCATION  # The desired file/directory containing the JSON files
   -o, [--output=OUTPUT]    # The desired output file/directory to write to

Formats JSON files on the file system

Example Formatting:

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request