Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsonapi-parse

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonapi-parse

Parses JSON API style responses into a more 'typical' JSON format

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
increased by0.15%
Maintainers
1
Weekly downloads
 
Created
Source

JSONAPI Parse

This library is currently complies and works with JSON API v1.0.

Install

bower install jsonapi-parse npm install jsonapi-parse

API Reference

jsonapi.parse(input)
OptionDescriptionDefault
inputA JSON string or JavaScript objectundefined

Parses the input provided if it follows the JSON API specification (v1.0). This library currently creates a new object for every nested resource object rather than pointing to the reference of the object form the included collection. This is in an effort to reduce difficult to trace bugs.

Currently it prevents circular references by keeping track of the "lineage" as it populates every new resource objects relationships. It will not set anything besides type and id for the related object.

Returns a new object with at least a data and jsonapi property. The data property should be the parsed version of the object graph included, and the jsonapi object should have an indicator for if it has been parsed and any other information the object contained previously.

Passing anything that is not a JSON string or JavaScript object will be returned as it was called with. Passing anything that does not conform to JSON API specification will also be returned as called with.

Example Usage

// JSON API structured object
var input = {
        data: [
            {
                id: '12klj',
                type: 'primary',
                attributes: { key: 'value', property: true }
            }
        ]
    },
    // JSON string of previous object
    stringified = JSON.stringify(input);

// Parsing a normal Javascript Object
window.jsonapi.parse(input);


// Parsing a JSON string
window.jsonapi.parse(stringified);

// Returns
// {
//     data: [ 
//         { id: '12klj', key: 'value', property: true }
//     ],
//     jsonapi: { parsed: true }
// }

Build

gulp build

This task currently concatenates, compresses (uglify), and moves the source files into the dist directory.

TODO

  • Add tests for the output of the parse method
  • Setup Travis CI for running the tests
  • Add npm package for parsing with Node

FAQs

Package last updated on 11 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc