
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
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.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.