jsonapi-flattener

1.0.10 • Public • Published

JSONAPI Flattener

Simple tool for flattening JSON api responses into simpler objects.

npm i jsonapi-flattener
yarn add jsonapi-flattener

Features:

  • Flattens the attributes object to properties on the parent

e.g.

{
  "data": 
  {
    "id": 1,
    "type": "person",
    "attributes": {
      "name": "bob",
      "age": 12
    }
  }
}

to

{
  "data": {
    "id": 1,
    "type": "person",
    "name": "bob",
    "age": 12
  }
}
  • Includes relationships as direct properties on the original object, maps in data from included resources

e.g.

{
  "data": {
    "id": 1,
    "type": "person",
    "realtionships": {
      "friend": {
        "data": {
          "id": 2,
          "type": "person"
        }
      }
    }
  },
  "included": [
    {
      "id": 2,
      "type": "person",
      "attributes": {
        "name": "sally",
        "age": 14
      }
    }
  ]
}

to

{
  "data": {
    "id": 1,
    "type": "person",
    "friend": {
      "id": 2,
      "type": "person",
      "name": "sally",
      "age": 14
    }
  }
}
  • Recursively include nested relationships

  • Handles collection types also

  • See index.spec.js for full list of test examples

Readme

Keywords

none

Package Sidebar

Install

npm i jsonapi-flattener

Weekly Downloads

124

Version

1.0.10

License

MIT

Unpacked Size

7.3 kB

Total Files

4

Last publish

Collaborators

  • dpix