https://github.com/guillaumebriday/json-api-response-converter
Normalize your JSON:API response
https://github.com/guillaumebriday/json-api-response-converter
json json-api json-api-normalizer vuex vuex-orm
Last synced: 2 months ago
JSON representation
Normalize your JSON:API response
- Host: GitHub
- URL: https://github.com/guillaumebriday/json-api-response-converter
- Owner: guillaumebriday
- License: mit
- Created: 2019-10-01T13:37:49.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-01-24T22:27:29.000Z (over 4 years ago)
- Last Synced: 2025-05-05T03:43:36.995Z (2 months ago)
- Topics: json, json-api, json-api-normalizer, vuex, vuex-orm
- Language: JavaScript
- Homepage: https://json-api-response-converter.netlify.app/
- Size: 1.32 MB
- Stars: 22
- Watchers: 2
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# JSON:API Response Converter
[](https://www.paypal.me/guillaumebriday)


[](https://www.npmjs.com/package/json-api-response-converter)
[](https://www.npmjs.com/package/json-api-response-converter)
[](https://github.com/guillaumebriday/json-api-response-converter)
[](https://json-api-response-converter.netlify.app)## Features
* Very small
* No dependencies
* Easy to use
* Compatible with [Vuex ORM](https://github.com/vuex-orm/vuex-orm)## Getting started
## Install
```bash
$ npm install json-api-response-converter --save# or
$ yarn add json-api-response-converter
```## Usage
```js
import JsonApiResponseConverter from 'json-api-response-converter'const response = {
data: [
{
id: '1',
type: 'articles',
attributes: {
title: 'This project is awesome'
},
relationships: {
author: {
data: { id: '1', type: 'author' }
},comments: {
data: [
{ id: '1', type: 'comment' },
{ id: '2', type: 'comment' }
]
}
}
}
],included: [
{
id: '1',
type: 'author',
attributes: {
name: 'Anakin'
}
},
{
id: '1',
type: 'comment',
attributes: {
body: 'First!'
}
},
{
id: '2',
type: 'comment',
attributes: {
body: 'Second!'
}
}
]
}const data = new JsonApiResponseConverter(response).formattedResponse
console.log(data)
/**
[
{
id: 1,
title: 'This project is awesome',author: {
id: 1,
name: 'Anakin'
},comments: [
{
id: 1,
body: 'First!'
},
{
id: 2,
body: 'Second!'
}
]
}
]
*/
```Many edges cases are tested in the [__tests__ folder](https://github.com/guillaumebriday/json-api-response-converter/tree/master/__tests__)
## Development
```bash
$ git clone https://github.com/guillaumebriday/json-api-response-converter
$ cd json-api-response-converter
$ yarn # or npm install
```You can run tests with [Jest](https://jestjs.io/):
```bash
$ yarn test # or npm run test
```Check the syntax with [ESLint](https://eslint.org/):
```bash
$ yarn lint
```## Contributing
Do not hesitate to contribute to the project by adapting or adding features ! Bug reports or pull requests are welcome.## Credits
Inspired by:
+ [https://github.com/SinestroWhite/Normalize-JSON-API](https://github.com/SinestroWhite/Normalize-JSON-API)
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).