jsonapi2simple

0.3.0 • Public • Published

BuildStatus

jsonapi2simple

Utility to allow conversion between simple JSON data and JSONAPI service based structure.

Usage

The conversion process will allow you to convert JSONAPI structures into more managable JSON. This tool was built for allowing front-end applications to work with a simplified structure during view/editing and then transform back to JSONAPI for server interactions.

var converter = require('jsonapi2simple');
var objectInfo = {
  'type': 'articles',
  'relates': {
    'author': 'people'
  }
};
var simpleContent = converter.toSimple({
  'data': {
    'id': '4f32132',
    'type': 'articles',
    'title': 'This Tool is Easy'
  }
}, objectInfo);
/*
simpleContent now contains:
{
  'id': '4f32132',
  'title': 'This Tool is Easy'
}
*/
var jsonApiContent = converter.toJsonApi(simple, objectInfo);
/*
jsonApiContent now contains:
{
  'data': {
    'id': '4f32132',
    'type': 'articles',
    'title': 'This Tool is Easy'
  }
}
*/

This can also be used for more complex structures. Usually with a front-end application the code that is interacting with the server will contain some meta data about the request such as its type and the resource's relationships to other resources.

For more complex structures or other use cases please refer to the included tests.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.3.1-beta.0-c64721080nightly
0.3.00latest

Version History

VersionDownloads (Last 7 Days)Published
0.3.1-beta.0-c64721080
0.3.00
0.2.00
0.1.00

Package Sidebar

Install

npm i jsonapi2simple

Weekly Downloads

0

Version

0.3.0

License

MIT

Last publish

Collaborators

  • jthoms1