jsonapi-util

1.5.0 • Public • Published

jsonapi-util codecov npm version CircleCI

Util functions for working with jsonapi 1.0 structures

Install

You can install using Node Package Manager (npm):

npm install jsonapi-util

Usage

var jsonapi = require('jsonapi-util')

var result = jsonapi.parse({
  data: [
    {
      type: "article",
      id: "man-of-steel",
      relationships: {
        author: {
          data: {
            type: "person",
            id: "superman"
          }
        }
      }
    }
  ],
  included: [
    {
      type: "person",
      id: "superman",
      attributes: {
        alias: 'Clark Kent',
        name: 'Kal-El'
      }
    }
  ]
});

console.log(result);
/* returns :>
 {
  data:[
    {
      type: "article",
      id: "man-of-steel",
      author: {
        type: "person",
        id: "superman",
        alias: "Clark Kent",
        name: "Kal-El"
      }
    }
  ]
}
*/

API

Methods

parse(obj)

Parse a jsonapi document object to resolves includes and returns a tree structured object.

isDocument(obj)

Verify if a object is a valid JSON API document

isResoucre(obj)

Verify if a object is a valid JSON API resource object

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i jsonapi-util

    Weekly Downloads

    0

    Version

    1.5.0

    License

    MIT

    Unpacked Size

    11.3 kB

    Total Files

    6

    Last publish

    Collaborators

    • alexaivars