GithubHelp home page GithubHelp logo

tjhillard / json-api-deserialize Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 4.0 1.01 MB

🕸 A deserializer for JSON:API responses

License: MIT License

JavaScript 37.98% TypeScript 62.02%
json-api deserializer normalizer utilities jsonapi jsonapi-client hacktoberfest

json-api-deserialize's People

Contributors

dependabot[bot] avatar tjhillard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

json-api-deserialize's Issues

Doesn't work if record has multiple relationships.

The json string below will only end up with the first record deserialised.
It works correctly if I remove the entity_type relationship.
Having done some inspecting with break-points, it looks like it is running into exceptions within normalizer which then stops the iteration from continuing.

message: "Property description must be an object: undefined"
stack: "TypeError: Property description must be an object: undefined↵    at Function.defineProperty (<anonymous>)↵    at normalizeGivenObject (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/normalizer/normalizer.func.js:79:24)↵    at normalizeGivenObject (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/normalizer/normalizer.func.js:58:21)↵    at normalizeGivenObject (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/normalizer/normalizer.func.js:75:17)↵    at normalizeGivenObject (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/normalizer/normalizer.func.js:70:17)↵    at normalizeGivenObject (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/normalizer/normalizer.func.js:31:25)↵    at Object.exports.normalize (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/normalizer/normalizer.func.js:87:5)↵    at Deserializer.getReturnObject (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/deserializer/deserializer.class.js:146:44)↵    at Deserializer.getDeserialized (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/deserializer/deserializer.class.js:65:25)↵    at exports.deserialize (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/deserializer/deserializer.func.js:5:44)"
__proto__: Error

Here's the JSONAPI raw data that causes this:

{
  "data": [
        {
            "type": "users",
            "id": "1",
            "attributes": {
                "active": true,
                "name": "Sherlock",
                "surname": "Holmes",
                "created": "2019-10-31T18:45:52+00:00",
                "modified": "2019-10-31T18:45:52+00:00"
            },
            "relationships": {
                "role": {
                    "links": {
                        "self": "/api/roles/2"
                    },
                    "data": {
                        "type": "roles",
                        "id": "2"
                    }
                },
                "entity-type": {
                    "links": {
                        "self": "/api/entity_types/1"
                    },
                    "data": {
                        "type": "entity-types",
                        "id": "1"
                    }
                }
            },
            "links": {
                "self": "/api/users/1"
            }
        },
        {
            "type": "users",
            "id": "3",
            "attributes": {
                "active": true,
                "name": "John",
                "surname": "Watson",
                "created": "2019-10-31T18:45:52+00:00",
                "modified": "2019-10-31T18:45:52+00:00"
            },
            "relationships": {
                "role": {
                    "links": {
                        "self": "/api/roles/3"
                    },
                    "data": {
                        "type": "roles",
                        "id": "3"
                    }
                },
                "entity-type": {
                    "links": {
                        "self": "/api/entity_types/1"
                    },
                    "data": {
                        "type": "entity-types",
                        "id": "1"
                    }
                }
            },
            "links": {
                "self": "/api/users/3"
            }
        }
    ],
    "included": [
        {
            "type": "roles",
            "id": "2",
            "attributes": {
                "name": "sidekick",
                "description": null,
                "created": "2019-10-31T18:45:52+00:00",
                "modified": "2019-10-31T18:45:52+00:00"
            },
            "links": {
                "self": "/api/roles/2"
            }
        },
        {
            "type": "entity-types",
            "id": "1",
            "attributes": {
                "name": "individual",
                "created": "2019-10-31T18:45:52+00:00",
                "modified": "2019-10-31T18:45:52+00:00"
            },
            "links": {
                "self": "/api/entity_types/1"
            }
        },
        {
            "type": "roles",
            "id": "3",
            "attributes": {
                "name": "hero",
                "description": null,
                "created": "2019-10-31T18:45:52+00:00",
                "modified": "2019-10-31T18:45:52+00:00"
            },
            "links": {
                "self": "/api/roles/3"
            }
        }
    ]
}

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.