{"id":32161122,"url":"https://github.com/shirren/json-api-lib","last_synced_at":"2025-10-21T13:50:48.289Z","repository":{"id":56844819,"uuid":"192854826","full_name":"shirren/json-api-lib","owner":"shirren","description":"JSON API Spec serialization library for Haskell","archived":false,"fork":false,"pushed_at":"2020-09-03T05:54:34.000Z","size":33,"stargazers_count":1,"open_issues_count":2,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-17T22:51:58.625Z","etag":null,"topics":["haskell-library","json","json-api","servant"],"latest_commit_sha":null,"homepage":null,"language":"Haskell","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/shirren.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-06-20T05:33:33.000Z","updated_at":"2020-09-03T15:31:14.000Z","dependencies_parsed_at":"2022-09-09T16:00:38.289Z","dependency_job_id":null,"html_url":"https://github.com/shirren/json-api-lib","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/shirren/json-api-lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirren%2Fjson-api-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirren%2Fjson-api-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirren%2Fjson-api-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirren%2Fjson-api-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shirren","download_url":"https://codeload.github.com/shirren/json-api-lib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shirren%2Fjson-api-lib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280272338,"owners_count":26302260,"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","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["haskell-library","json","json-api","servant"],"created_at":"2025-10-21T13:50:41.325Z","updated_at":"2025-10-21T13:50:48.284Z","avatar_url":"https://github.com/shirren.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Haskell Implementation of the JSON-API specification\n\n### Attribution\n\nThis codebase is a fork of the original [json-api](https://github.com/toddmohney/json-api) lib authored by [Todd Mohney](https://github.com/toddmohney).\n\n#### The specification\n\nFind the specification [here](http://jsonapi.org/)\n\n#### Example usage\n\nLet's start with a simple User resource record:\n\n```Haskell\ndata UserResource = UserResource\n  { resourceId        :: Text\n  , emailAddress :: Text\n  , firstName :: Text\n  , middleName :: Maybe Text\n  , lastName  :: Text\n  } deriving (Eq, Show)\n\n$(deriveJSON defaultOptions ''UserResource)\n\ninstance ResourcefulEntity UserResource where\n  resourceIdentifier = resourceId\n  resourceType _ = \"users\"\n  resourceLinks = Just . JSONApi.showLink\n  resourceMetaData _ = Nothing\n  resourceRelationships _ = Nothing\n```\n\nFrom this, we can use the `json-api` package to produce a payload conformant\nto the [JSON-API specification](http://jsonapi.org/) like so:\n\n```Haskell\n-- Import the JSON API\nimport qualified Network.JSONApi as JSONApi\n-- Builds the Document which will be serialized as our\n-- web server's response payload\nlet userResource = UserResource {\n    resourceId = \"8b384d842a8b33fdcaf6207ad45b62c9\"\n  , emailAddress = \"john@doe.com\"\n  , firstName = \"John\"\n  , middleName = \"Adrian\"\n  , lastName = \"Doe\"\n  }\nJSONApi.mkDocument userResource Nothing Nothing\n```\n\nWhen delivered as a response from a web server, for example, we get a payload\nthat looks like this:\n\n```JSON\n{\n  \"data\": {\n      \"attributes\": {\n          \"resourceId\": \"8b384d842a8b33fdcaf6207ad45b62c9\",\n          \"middleName\": \"Adrian\",\n          \"lastName\": \"Doe\",\n          \"emailAddress\": \"john@doe.com\",\n          \"firstName\": \"John\"\n      },\n      \"relationships\": null,\n      \"id\": \"8b384d842a8b33fdcaf6207ad45b62c9\",\n      \"meta\": null,\n      \"type\": \"users\",\n      \"links\": {\n          \"self\": \"/users/8b384d842a8b33fdcaf6207ad45b62c9\"\n      }\n  },\n  \"meta\": null,\n  \"included\": [],\n  \"links\": null\n}\n```\n\nNow suppose you want to send back a collection of resources (e.g: User resources).\n\n```Haskell\n-- Import the JSON API\nimport qualified Network.JSONApi as JSONApi\n-- Builds the Document which will be serialized as our\n-- web server's response payload\nlet userResource1 = UserResource {\n    resourceId = \"8b384d842a8b33fdcaf6207ad45b62c9\"\n  , emailAddress = \"john@doe.com\"\n  , firstName = \"John\"\n  , middleName = Nothing\n  , lastName = \"Doe\"\n  }\nlet userResource2 = UserResource {\n    resourceId = \"8b384d842a8b33fdcaf6207ad45b62c9\"\n  , emailAddress = \"jane@doe.com\"\n  , firstName = \"Jane\"\n  , middleName = Nothing\n  , lastName = \"Doe\"\n  }\nJSONApi.mkDocuments [userResource1, userResource2] Nothing Nothing\n```\n\nWhen delivered as a response from a web server, for example, we get a payload\nthat looks like this:\n\n```JSON\n{\n  \"data\": [{\n      \"attributes\": {\n          \"resourceId\": \"8b384d842a8b33fdcaf6207ad45b62c9\",\n          \"middleName\": \"Adrian\",\n          \"lastName\": \"Doe\",\n          \"emailAddress\": \"john@doe.com\",\n          \"firstName\": \"John\"\n      },\n      \"relationships\": null,\n      \"id\": \"8b384d842a8b33fdcaf6207ad45b62c9\",\n      \"meta\": null,\n      \"type\": \"users\",\n      \"links\": {\n          \"self\": \"/users/8b384d842a8b33fdcaf6207ad45b62c9\"\n      }},{\n      \"attributes\": {\n          \"resourceId\": \"8b384d842a8b33fdcaf6207ad45b62c8\",\n          \"lastName\": \"Doe\",\n          \"emailAddress\": \"jane@doe.com\",\n          \"firstName\": \"Jane\"\n      },\n      \"relationships\": null,\n      \"id\": \"8b384d842a8b33fdcaf6207ad45b62c8\",\n      \"meta\": null,\n      \"type\": \"users\",\n      \"links\": {\n          \"self\": \"/users/8b384d842a8b33fdcaf6207ad45b62c8\"\n      }\n    }]\n  },\n  \"meta\": null,\n  \"included\": [],\n  \"links\": null\n}\n```\n\n#### Example Project\n\nThere is an [example project](https://github.com/shirren/servant-store) illustrating how the library can be used in the context of a web application.\n\n#### Hackage\n\nModule documentation can be found on [Hackage](http://hackage.haskell.org/package/json-api-lib)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshirren%2Fjson-api-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshirren%2Fjson-api-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshirren%2Fjson-api-lib/lists"}