luke-hawk / simple-jsonapi-deserializer

Straight forward, zero config deserialization of JSON API resources.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

simple-jsonapi-deserializer

Painless, zero config JSON API deserialization.

Installation

Add to you application's Gemfile

gem 'simple-jsonapi-deserializer'

and install

$ bundle

or install it directly

$ gem install 'simple-jsonapi-deserializer'

Usage

SimpleJSONAPIDeserializer.deserialize(json_api_hash)

Examples

json_api_hash = {
  'data' => {
    'id' => '1234',
    'type' => 'planets',
    'attributes' => {
      'name' => 'Earth'
    },
    'relationships' => {
      'satellites' => {
        'data' => [
          {
            'id' => '914',
            'type' => 'satellites'
          }
        ]
      }
    }
  },
  'included' => [
    {
      'id' => '914',
      'type' => 'satellites',
      'attributes' => {
        'name' => 'Moon'
      }
    }
  ]
}

SimpleJSONAPIDeserializer.deserialize(json_api_hash)

# =>
# {
#   "id" => "1234",
#   "type" => "planets",
#   "name" => "Earth",
#   "satellites" => [
#     {
#       "id" => "914",
#       "type" => "satellites",
#       "name" => "Moon"
#     }
#   ]
# }

License

MIT

About

Straight forward, zero config deserialization of JSON API resources.

License:MIT License


Languages

Language:Ruby 100.0%