{"id":21031293,"url":"https://github.com/workable/jsonapi","last_synced_at":"2026-01-30T01:41:15.272Z","repository":{"id":43993434,"uuid":"240236683","full_name":"Workable/jsonapi","owner":"Workable","description":null,"archived":false,"fork":false,"pushed_at":"2024-04-15T14:55:27.000Z","size":1693,"stargazers_count":1,"open_issues_count":16,"forks_count":1,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-01-20T15:22:22.534Z","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/Workable.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-13T10:45:03.000Z","updated_at":"2020-06-18T08:38:32.000Z","dependencies_parsed_at":"2024-11-19T12:38:29.194Z","dependency_job_id":"d78845d5-46d1-4ca4-93d0-8ec79a828068","html_url":"https://github.com/Workable/jsonapi","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Workable%2Fjsonapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Workable%2Fjsonapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Workable%2Fjsonapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Workable%2Fjsonapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Workable","download_url":"https://codeload.github.com/Workable/jsonapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243471458,"owners_count":20296121,"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":"2024-11-19T12:27:08.396Z","updated_at":"2026-01-30T01:41:15.197Z","avatar_url":"https://github.com/Workable.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jsonapi\n\njsonapi provides the url composition, serialize and deserialize functionality that implements the JSON:API schema.\n\nRead more about [JSON:API schema](https://jsonapi.org/)\n\n## installing\n\nUsing npm:\n\n```\n$ npm install @workablehr/jsonapi\n```\n\n## Basic usage\n\n```javascript\nimport {serialize} from '@workablehr/jsonapi';\n\nconst payload = serialize(\"sourceName\", {\n  attr1: \"value1\",\n  attr2: \"value2\"\n}).value();\nconst url = makeUrl(\"sourceName\")\n  .include(\"source2\")\n  .filter(\"fieldName\", [\"fieldValue\"]);\n\nrequest(url, { body: payload })\n  .then(deserialize)\n  .catch(error =\u003e {\n    throw deserialize(error);\n  });\n```\n\n## Serialize\n\nA helper for generating JSON:API schema objects.\n\n```javascript\nimport {serialize} from '@workablehr/jsonapi';\n\nserialize(\"job\", jobAttrs)\n  .include(\"account\", accountId)\n  .meta(metaAttrs)\n  .value();\n```\n\n## Deserialize\n\nA helper for deserializing JSON:API schema objects.\n\n```javascript\nimport {deserialize} from '@workablehr/jsonapi';\n\ndeserialize({\n  data: [\n    {\n      id: 1,\n      type: \"type1\",\n      attributes: { attr1: \"value1\" },\n      relationships: { type2: { data: { id: 2, type: \"type2\" } } }\n    }\n  ],\n  included: [{ type: \"type2\", id: 2, attributes: { attr2: \"value2\" } }]\n});\n\n// {\n//   type1: [{ id: 1, attr1: \"value1\", type: \"type1\", type2Id: 2 }],\n//   type2: { id: 2, attr2: \"value2\", type: \"type2\" }\n// }\n```\n\n## makeUrl\n\nA helper for generating search queries according to JSON:API schema\n\n```javascript\nimport {makeUrl} from '@workablehr/jsonapi';\n\nmakeUrl(\"resource.com\")\n  .include([\"account\"])\n  .filter(\"staffing\", true)\n  .only(\"job\", [\"title\", \"description\"])\n  .only(\"account\", \"name\")\n  .page(3)\n  .limit(15)\n  .sort([\"title\", \"-description\"])\n  .search(\"some term\")\n  .value();\n\n// resource.com?include=account\u0026filter[staffing]=true\u0026fields[job]=title,description\u0026fields[account]=name\u0026page[number]=3\u0026page[size]=15\u0026sort=title,-description\n```\n\n## Recommended usage\n\nThe jsonapi matches perfectly with the `@workablehr/request` middlewares.\nYou can easily compose a json api request that returns a deserialized response.\n\n```javascript\nimport request from \"@workablehr/request\";\nimport withJsonapi from \"@workablehr/jsonapi\";\n\nconst jsonapiRequest = withJsonapi(request);\n\njsonapiRequest(\"resource.com\").then(response =\u003e {\n  console.log(response);\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkable%2Fjsonapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworkable%2Fjsonapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkable%2Fjsonapi/lists"}