classy_json
classy_json copied to clipboard
ClassyJSON
ClassyJSON
This gem takes a stringified JSON response(before parse) and objectifys it. For the record, I don't really believe in objectification.
It works like this:

Installation
Add this line to your application's Gemfile:
gem 'classy_json'
And then execute:
$ bundle
Or install it yourself as:
$ gem install classy_json
Usage
Typically you'll be able to handle very large and nested JSON payloads with simplicity:
require 'classy_json'
resp = Net::HTTP.get(URI('some_json_api')
results = ClassyJSON.convert(resp)
When a single JSON object is in the response
resp = Net::HTTP.get(URI('https://jobs.github.com/positions/eef0892e-a555-11e4-903f-115f3ec6fcd0.json'))
results = ClassyJSON.convert(resp, 'job')
results.job.company
=> "Code Club"
If your response is only an array, you'll need to specify the object we're creating with a secondary argument like so:
resp = Net::HTTP.get(URI('https://jobs.github.com/positions.json?description=software&location='))
jobs = ClassyJSON.convert(resp, 'jobs')
=> [Array, of, jobs]
Contributing
- Fork it ( https://github.com/[my-github-username]/classy_json/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request