
Product
Introducing Reachability for PHP
Reachability analysis for PHP is now available in experimental, helping teams identify which vulnerabilities are actually exploitable.
json_pretty_generate
Advanced tools
Small utility method for pretty generating JSON
Add this line to your application's Gemfile:
gem 'json_pretty_generate'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install json_pretty_generate
There is a single ::call method.
When the argument is a Hash JSON will be returned with line breaks
obj = { a: 1 }
JSONPrettyGenerate.(obj)
# => "{\n \"a\": 1\n}"
When the argument is JSON it returns JSON with line breaks
obj = "{\"a\":1}"
JSONPrettyGenerate.(obj)
# => "{\n \"a\": 1\n}"
When the argument is a string that is not JSON it returns the argument
obj = "a=1"
JSONPrettyGenerate.(obj)
# => "a=1"
When the argument type is not a String or Hash it will return nil
obj = 1
JSONPrettyGenerate.(obj)
# => nil
You can use a block to filter the obj to a subset of the data. Strings or symbols can be passed to the block argument.
obj = { data: { body: { a: 1 } } }
JSONPrettyGenerate.(obj) { |o| o[:data][:body] }
# => "{\n \"a\": 1\n}"
To run the specs
$ bundle exec rake
Bug reports and pull requests are welcome on GitHub at https://github.com/nikkypx/json_pretty_generate.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that json_pretty_generate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Reachability analysis for PHP is now available in experimental, helping teams identify which vulnerabilities are actually exploitable.

Product
Export Socket alert data to your own cloud storage in JSON, CSV, or Parquet, with flexible snapshot or incremental delivery.

Research
/Security News
Bitwarden CLI 2026.4.0 was compromised in the Checkmarx supply chain campaign after attackers abused a GitHub Action in Bitwarden’s CI/CD pipeline.