# TidyJson [![Travis Build Status][travis_build_status_badge]][travis_build_status] [![Circle CI Build Status][cci_build_status_badge]][cci_build_status] ![Gem Version][gem_version_badge] A mixin providing (recursive) JSON serialization and pretty printing. ### Installation ```bash $ gem install tidy_json ``` Or, in your `Gemfile`: ```ruby source 'https://rubygems.org' # ... gem 'tidy_json' # ... ``` ### Example ```ruby require 'tidy_json' class Jsonable attr_reader :a, :b def initialize @a = { a: 'uno', b: 'dos', c: ['I', 'II', 'III', ['i.', 'ii.', 'iii.', { 'ichi': "\u{4e00}", 'ni': "\u{4e8c}", 'san': "\u{4e09}", 'yon': "\u{56db}" }]] } @b = { a: 1, b: ['two', 3, 'IV'] } end end complex_object = Jsonable.new puts JSON.parse complex_object.stringify # => {"class"=>"Jsonable", "a"=>{"a"=>"uno", "b"=>"dos", "c"=>["I", "II", "III", ["i.", "ii.", "iii.", {"ichi"=>"一", "ni"=>"二", "san"=>"三", "yon"=>"四"}]]}, "b"=>{"a"=>1, "b"=>["two", 3, "IV"]}} puts complex_object.to_tidy_json # { # "class": "Jsonable", # "a": # { # "a": "uno", # "b": "dos", # "c": # [ # "I", # "II", # "III", # [ # "i.", # "ii.", # "iii.", # { # "ichi":"一", # "ni":"二", # "san":"三", # "yon":"四" # } # ] # ] # }, # "b": # { # "a": 1, # "b": # [ # "two", # 3, # "IV" # ] # } # } # => nil ``` ### Dependencies #### Runtime - [json](https://rubygems.org/gems/json) ~> 2.2 #### Building - [bundler](https://rubygems.org/gems/bundler) ~> 1.17 - [minitest](https://rubygems.org/gems/minitest) ~> 5.0 - [yard](https://rubygems.org/gems/yard) ~> 0.9 ### License [MIT](https://opensource.org/licenses/MIT) [travis_build_status]: https://travis-ci.com/rdipardo/tidy_json [cci_build_status]: https://circleci.com/gh/rdipardo/tidy_json [travis_build_status_badge]: https://travis-ci.com/rdipardo/tidy_json.svg [cci_build_status_badge]: https://circleci.com/gh/rdipardo/tidy_json.svg?style=svg [gem_version_badge]: https://img.shields.io/gem/v/tidy_json