JsonApiNormalizer
A simple way to convert datasets based on JSON API specification
Installation
Add this line to your application's Gemfile:
gem 'json_api_normalizer'
And then execute:
$ bundle
Or install it yourself as:
$ gem install json_api_normalizer
Usage
require 'json'
require 'json_api_normalizer'
json = JSON.parse(File.read('articles.json'))
data = JsonApiNormalizer.parse(json)
puts JSON.pretty_generate(data) # =>
{
"id": "1",
"title": "JSON API paints my bikeshed!",
"author": {
"id": "9",
"first-name": "Dan",
"last-name": "Gebhardt",
"twitter": "dgeb"
},
"comments": [
{
"id": "5",
"body": "First!",
"author": {
"id": "2",
"first-name": "John",
"last-name": "Travolta",
"twitter": "johnt"
}
},
{
"id": "12",
"body": "I like XML better",
"author": {
"id": "9",
"first-name": "Dan",
"last-name": "Gebhardt",
"twitter": "dgeb"
}
}
]
}
Contributing
- Fork the project.
- Add a breaking test for your change.
- Make the tests pass.
- Run
rubocop -a
- Push your fork.
- Submit a pull request.
License
The gem is available as open source under the terms of the MIT License.