jsonapi-flattener
v1.0.10
Published
Simple tool for flattening JSON api responses into simpler objects.
Downloads
1,225
Readme
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