Giter VIP home page Giter VIP logo

jsonapi-parse's Introduction

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)

Option Description Default
input A JSON string or JavaScript object undefined

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

jsonapi-parse's People

Contributors

grahamlyus avatar pjfreeze avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.