{"id":24014945,"url":"https://github.com/maxatwork/jsonapi-normalizr","last_synced_at":"2025-06-17T03:07:21.797Z","repository":{"id":57285625,"uuid":"80757323","full_name":"maxatwork/jsonapi-normalizr","owner":"maxatwork","description":"Schema-based JSON API data parser","archived":false,"fork":false,"pushed_at":"2018-05-07T20:06:31.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-02T15:17:21.007Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxatwork.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-02T18:49:55.000Z","updated_at":"2019-07-11T13:52:35.000Z","dependencies_parsed_at":"2022-09-10T10:01:30.966Z","dependency_job_id":null,"html_url":"https://github.com/maxatwork/jsonapi-normalizr","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/maxatwork/jsonapi-normalizr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxatwork%2Fjsonapi-normalizr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxatwork%2Fjsonapi-normalizr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxatwork%2Fjsonapi-normalizr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxatwork%2Fjsonapi-normalizr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxatwork","download_url":"https://codeload.github.com/maxatwork/jsonapi-normalizr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxatwork%2Fjsonapi-normalizr/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260281568,"owners_count":22985629,"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":[],"created_at":"2025-01-08T07:38:11.484Z","updated_at":"2025-06-17T03:07:21.762Z","avatar_url":"https://github.com/maxatwork.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Schema-based JSON API data parser\n\nQuick and dirty implementation. Do not use in production!\n\n## Usage\n\n### Installation\n\n```bash\nnpm i --save jsonapi-normalizr\n```\n\n### Imports\n\n```javascript\nimport {schema, fields, normalize} from 'jsonapi-normalizr'\n```\n\n### Schemas\n\n```javascript\nconst userSchema = schema('users', {\n    email: fields.string(),\n    fullName: fields.string({fromName: 'full_name'})\n})\n\nconst commentSchema = schema('comments', {\n    author: fields.relationship(userSchema),\n    text: fields.string()\n}, {jsonApiType: 'blog_comments'})\n\nconst postSchema = schema('posts', {\n    created: fields.date(),\n    title: fields.string(),\n    text: fields.string(),\n    comments: fields.relationship(commentSchema, {many: true})\n}, {jsonApiType: 'blog_posts'})\n```\n\n### Source data\n\n```javascript\nconst jsonApiData = {\n    data: {\n        id: '1',\n        type: 'blog_posts',\n        attributes: {\n            created: '2017-02-02T12:30:41Z',\n            title: 'Hello world!',\n            text: 'This is the post about jsonapi-normalizr'\n        },\n        relationships: {\n            comments: {\n                data: [\n                    {type: 'blog_comments', id: '1'},\n                    {type: 'blog_comments', id: '2'}\n                ]\n            }\n        }\n    },\n    included: [\n        {\n            id: '1',\n            type: 'blog_comments',\n            attributes: {text: 'First comment'},\n            relationships: {\n                author: {data: {type: 'users', id: '1'}}\n            }\n        },\n        {\n            id: '2',\n            type: 'blog_comments',\n            attributes: {text: 'Second comment'},\n            relationships: {\n                author: {data: {type: 'users', id: '2'}}\n            }\n        },\n        {\n            id: '1',\n            type: 'users',\n            attributes: {email: 'user1@example.com', full_name: 'John Doe'}\n        },\n        {\n            id: '2',\n            type: 'users',\n            attributes: {email: 'user2@example.com', full_name: 'Dow Jones'}\n        }\n    ]\n}\n```\n\n### Parsing\n\n```javascript\nconst normalized = normalize(\n    postSchema({include: ['comments', 'comments.author']}),\n    jsonApiData\n)\n```\n\n### Result data\n\n```javascript\n{\n    \"result\": {\"type\": \"posts\", \"id\": \"1\"},\n    \"entities\": {\n        \"posts\": {\n            \"1\": {\n                \"id\": \"1\",\n                \"created\": new Date('2017-02-02T12:30:41Z'),\n                \"title\": \"Hello world!\",\n                \"text\": \"This is the post about jsonapi-normalizr\",\n                \"comments\": [\n                    {\"type\": \"comments\", \"id\": \"1\"},\n                    {\"type\": \"comments\", \"id\": \"2\"}\n                ]\n            }\n        },\n        \"comments\": {\n            \"1\": {\n                \"id\": \"1\",\n                \"author\": {\"type\": \"users\", \"id\": \"1\"},\n                \"text\": \"First comment\"\n            },\n            \"2\": {\n                \"id\": \"2\",\n                \"author\": {\"type\": \"users\", \"id\": \"2\"},\n                \"text\": \"Second comment\"\n            }\n        },\n        \"users\": {\n            \"1\": {\n                \"id\": \"1\",\n                \"email\": \"user1@example.com\",\n                \"fullName\": \"John Doe\"\n            },\n            \"2\": {\n                \"id\": \"2\",\n                \"email\": \"user2@example.com\",\n                \"fullName\": \"Dow Jones\"\n            }\n        }\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxatwork%2Fjsonapi-normalizr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxatwork%2Fjsonapi-normalizr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxatwork%2Fjsonapi-normalizr/lists"}