{"id":30143140,"url":"https://github.com/juspay/purescript-foreign-generic","last_synced_at":"2026-02-08T07:32:52.429Z","repository":{"id":302338755,"uuid":"614390725","full_name":"juspay/purescript-foreign-generic","owner":"juspay","description":null,"archived":false,"fork":false,"pushed_at":"2023-03-15T13:52:31.000Z","size":76,"stargazers_count":0,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-07-01T21:25:39.271Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PureScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juspay.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,"zenodo":null}},"created_at":"2023-03-15T13:48:02.000Z","updated_at":"2023-04-17T17:44:47.000Z","dependencies_parsed_at":"2025-07-01T21:26:19.362Z","dependency_job_id":"55d9c81c-3c46-48f6-a2ff-1005f9cf3318","html_url":"https://github.com/juspay/purescript-foreign-generic","commit_stats":null,"previous_names":["juspay/purescript-foreign-generic"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/juspay/purescript-foreign-generic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juspay%2Fpurescript-foreign-generic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juspay%2Fpurescript-foreign-generic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juspay%2Fpurescript-foreign-generic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juspay%2Fpurescript-foreign-generic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juspay","download_url":"https://codeload.github.com/juspay/purescript-foreign-generic/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juspay%2Fpurescript-foreign-generic/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269843701,"owners_count":24484116,"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-08-11T02:00:10.019Z","response_time":75,"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":[],"created_at":"2025-08-11T06:50:06.577Z","updated_at":"2026-02-08T07:32:47.410Z","avatar_url":"https://github.com/juspay.png","language":"PureScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# purescript-foreign-generic\n\n[![Build Status](https://travis-ci.org/paf31/purescript-foreign-generic.svg?branch=master)](https://travis-ci.org/paf31/purescript-foreign-generic)\n\nGeneric deriving for `purescript-foreign`.\n\n- [Module Documentation](generated-docs/Foreign/Generic.md)\n- [Example](test/Main.purs)\n- [Further examples in this repo](https://github.com/justinwoo/purescript-howto-foreign-generic)\n\n## Example Usage\n\nFirst, define some data type and derive `Generic`:\n\n```purescript\n\u003e import Prelude\n\u003e import Data.Generic.Rep (class Generic)\n\u003e import Data.Show.Generic (genericShow)\n\n\u003e newtype MyRecord = MyRecord { a :: Int }\n\u003e derive instance genericMyRecord :: Generic MyRecord _\n\u003e instance showMyRecord :: Show MyRecord where show = genericShow\n```\n\nTo encode JSON, use `genericEncodeJSON`:\n\n```purescript\n\u003e import Foreign.Generic (defaultOptions, genericEncodeJSON)\n\n\u003e opts = defaultOptions { unwrapSingleConstructors = true }\n\n\u003e genericEncodeJSON opts (MyRecord { a: 1 })\n\"{\\\"a\\\":1}\"\n```\n\nAnd to decode JSON, use `genericDecodeJSON`:\n\n```purescript\n\u003e import Control.Monad.Except (runExcept)\n\u003e import Foreign.Generic (genericDecodeJSON)\n\n\u003e runExcept (genericDecodeJSON opts \"{\\\"a\\\":1}\" :: _ MyRecord)\n(Right (MyRecord { a: 1 }))\n```\n\nBadly formed JSON will result in a useful error, which can be inspected or pretty-printed:\n\n```purescript\n\u003e import Data.Bifunctor (lmap)\n\u003e import Foreign (renderForeignError)\n\n\u003e lmap (map renderForeignError) $ runExcept (genericDecodeJSON opts \"{\\\"a\\\":\\\"abc\\\"}\" :: _ MyRecord)\n(Left\n  (NonEmptyList\n    (NonEmpty\n      \"Error at array index 0: (ErrorAtProperty \\\"a\\\" (TypeMismatch \\\"Int\\\" \\\"String\\\"))\"\n      Nil)))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuspay%2Fpurescript-foreign-generic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuspay%2Fpurescript-foreign-generic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuspay%2Fpurescript-foreign-generic/lists"}