1.0.10 • Published 3 years ago

jsonapi-flattener v1.0.10

Weekly downloads
394
License
MIT
Repository
github
Last release
3 years ago

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

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago