{"id":19680795,"url":"https://github.com/lysyi3m/json-api-normalizer","last_synced_at":"2025-04-29T04:31:39.170Z","repository":{"id":48252089,"uuid":"243711821","full_name":"lysyi3m/json-api-normalizer","owner":"lysyi3m","description":"Utility to normalize JSON:API data with ease","archived":false,"fork":false,"pushed_at":"2021-08-04T09:18:15.000Z","size":683,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-18T20:16:04.173Z","etag":null,"topics":["json-api","jsonapi","normalizer"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lysyi3m.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-28T08:17:10.000Z","updated_at":"2024-03-09T07:42:20.000Z","dependencies_parsed_at":"2022-08-31T17:14:38.433Z","dependency_job_id":null,"html_url":"https://github.com/lysyi3m/json-api-normalizer","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lysyi3m%2Fjson-api-normalizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lysyi3m%2Fjson-api-normalizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lysyi3m%2Fjson-api-normalizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lysyi3m%2Fjson-api-normalizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lysyi3m","download_url":"https://codeload.github.com/lysyi3m/json-api-normalizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251432857,"owners_count":21588668,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json-api","jsonapi","normalizer"],"created_at":"2024-11-11T18:06:08.446Z","updated_at":"2025-04-29T04:31:38.876Z","avatar_url":"https://github.com/lysyi3m.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-api-normalizer\n\nUtility to normalize JSON:API data with ease\n\n![Node.js CI](https://github.com/lysyi3m/json-api-normalizer/workflows/Node.js%20CI/badge.svg?branch=master)\n[![npm version](https://badge.fury.io/js/%40lysyi3m%2Fjson-api-normalizer.svg)](https://badge.fury.io/js/%40lysyi3m%2Fjson-api-normalizer)\n\n## Description\n\njson-api-normalizer helps to processing [JSON:API](https://jsonapi.org/) data into more developer-friendly form for further usage. It fully supports [latest JSON:API specification](https://jsonapi.org/format/) including one-to-one \u0026 one-to-many relationships, so you don't need to manually format each response to work with regular resource collections. It's main feature is correct exctracting so called [\"sparse fieldsets\"](https://jsonapi.org/format/#fetching-sparse-fieldsets) and nesting them under corresponding resource.\n\n## Installation\n\n```sh\n$ npm install @lysyi3m/json-api-normalizer\n```\n\nor using [Yarn](https://yarnpkg.com/):\n```sh\n$ yarn add @lysyi3m/json-api-normalizer\n```\n\n## Usage\n\n```js\nimport normalizer from '@lysyi3m/json-api-normalizer';\n\n// make a request tou your API endpoint and get response\n\nconst result = normalizer(response.data);\n\nconsole.log(result.data) // data is normalized resources with exctracted \u0026 nested relationships\nconsole.log(result.meta) // meta object\nconsole.log(result.links) // links object\n```\n\n## Examples\n\n### Basic\n\nAssuming endpoint `/articles?include=author`, your response data would be like this:\n\n```json\n{\n  \"data\": [{\n    \"type\": \"articles\",\n    \"id\": \"1\",\n    \"attributes\": {\n      \"title\": \"JSON:API paints my bikeshed!\",\n      \"body\": \"The shortest article. Ever.\",\n      \"created\": \"2015-05-22T14:56:29.000Z\",\n      \"updated\": \"2015-05-22T14:56:28.000Z\"\n    },\n    \"relationships\": {\n      \"author\": {\n        \"data\": {\"id\": \"42\", \"type\": \"people\"}\n      }\n    }\n  }],\n  \"included\": [\n    {\n      \"type\": \"people\",\n      \"id\": \"42\",\n      \"attributes\": {\n        \"name\": \"John\",\n        \"age\": 80,\n        \"gender\": \"male\"\n      }\n    }\n  ]\n}\n```\n\nAnd after normalization:\n```json\n{\n  \"data\": [\n    {\n      \"id\": \"1\",\n      \"title\": \"JSON:API paints my bikeshed!\",\n      \"body\": \"The shortest article. Ever.\",\n      \"created\": \"2015-05-22T14:56:29.000Z\",\n      \"updated\": \"2015-05-22T14:56:28.000Z\",\n      \"author\": {\n        \"id\": \"42\",\n        \"name\": \"John\",\n        \"age\": \"80\",\n        \"gender\": \"male\"\n      }\n    }\n  ]\n}\n```\n\n### Complex relationships\n\nIn case one-to-one, one-to-many or nested relationships (i.e., when relationship resource has its own relationships), json-api-normalizer will proccess them at once, using matching by resource id \u0026 type altogether.\n\nAssuming endpoint `/articles?include=author,comments`, your response data would be like this:\n\n```json\n{\n  \"data\": [{\n    \"type\": \"articles\",\n    \"id\": \"1\",\n    \"attributes\": {\n      \"title\": \"JSON:API paints my bikeshed!\"\n    },\n    \"links\": {\n      \"self\": \"http://example.com/articles/1\"\n    },\n    \"relationships\": {\n      \"author\": {\n        \"links\": {\n          \"self\": \"http://example.com/articles/1/relationships/author\",\n          \"related\": \"http://example.com/articles/1/author\"\n        },\n        \"data\": { \"type\": \"people\", \"id\": \"9\" }\n      },\n      \"comments\": {\n        \"links\": {\n          \"self\": \"http://example.com/articles/1/relationships/comments\",\n          \"related\": \"http://example.com/articles/1/comments\"\n        },\n        \"data\": [\n          { \"type\": \"comments\", \"id\": \"5\" },\n          { \"type\": \"comments\", \"id\": \"12\" }\n        ]\n      }\n    }\n  }],\n  \"included\": [{\n    \"type\": \"people\",\n    \"id\": \"9\",\n    \"attributes\": {\n      \"first-name\": \"Dan\",\n      \"last-name\": \"Gebhardt\",\n      \"twitter\": \"dgeb\"\n    },\n    \"links\": {\n      \"self\": \"http://example.com/people/9\"\n    }\n  }, {\n    \"type\": \"comments\",\n    \"id\": \"5\",\n    \"attributes\": {\n      \"body\": \"First!\"\n    },\n    \"relationships\": {\n      \"author\": {\n        \"data\": { \"type\": \"people\", \"id\": \"2\" }\n      }\n    },\n    \"links\": {\n      \"self\": \"http://example.com/comments/5\"\n    }\n  }, {\n    \"type\": \"comments\",\n    \"id\": \"12\",\n    \"attributes\": {\n      \"body\": \"I like XML better\"\n    },\n    \"relationships\": {\n      \"author\": {\n        \"data\": { \"type\": \"people\", \"id\": \"9\" }\n      }\n    },\n    \"links\": {\n      \"self\": \"http://example.com/comments/12\"\n    }\n  }]\n}\n```\n\nAnd after normalization:\n\n```json\n{\n  \"data\":[\n    {\n      \"id\":\"1\",\n      \"links\":{\n        \"self\":\"http://example.com/articles/1\"\n      },\n      \"title\":\"JSON:API paints my bikeshed!\",\n      \"author\":{\n        \"id\":\"9\",\n        \"links\":{\n          \"self\":\"http://example.com/people/9\"\n        },\n        \"first-name\":\"Dan\",\n        \"last-name\":\"Gebhardt\",\n        \"twitter\":\"dgeb\"\n      },\n      \"comments\":[\n        {\n          \"id\":\"5\",\n          \"links\":{\n            \"self\":\"http://example.com/comments/5\"\n          },\n          \"body\":\"First!\",\n        },\n        {\n          \"id\":\"12\",\n          \"links\":{\n            \"self\":\"http://example.com/comments/12\"\n          },\n          \"body\":\"I like XML better\",\n          \"author\":{\n            \"id\":\"9\",\n            \"links\":{\n              \"self\":\"http://example.com/people/9\"\n            },\n            \"first-name\":\"Dan\",\n            \"last-name\":\"Gebhardt\",\n            \"twitter\":\"dgeb\"\n          }\n        }\n      ]\n    }\n  ],\n}\n```\n\n## Available options\n\n### `Camelize`\n\nBy default json-api-normalizer does not transform data keys. If `camelize` option is set to `true` all keys will be converted to [camelCase](https://wikipedia.org/wiki/Camel_case).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flysyi3m%2Fjson-api-normalizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flysyi3m%2Fjson-api-normalizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flysyi3m%2Fjson-api-normalizer/lists"}