jsonapi-util
v1.5.0
Published
Util for handling and parsing jsonapi response object
Downloads
9
Maintainers
Readme
jsonapi-util
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