{"id":26076865,"url":"https://github.com/purescript-contrib/purescript-argonaut-generic","last_synced_at":"2025-10-19T17:51:50.647Z","repository":{"id":20059047,"uuid":"88613975","full_name":"purescript-contrib/purescript-argonaut-generic","owner":"purescript-contrib","description":"Generic encoding and decoding functions for data types with a Generic.Rep instance","archived":false,"fork":false,"pushed_at":"2022-04-27T23:09:10.000Z","size":168,"stargazers_count":22,"open_issues_count":3,"forks_count":25,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-03-11T03:01:46.256Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PureScript","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/purescript-contrib.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-18T10:46:02.000Z","updated_at":"2023-07-25T14:08:29.000Z","dependencies_parsed_at":"2022-07-23T14:46:22.824Z","dependency_job_id":null,"html_url":"https://github.com/purescript-contrib/purescript-argonaut-generic","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purescript-contrib%2Fpurescript-argonaut-generic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purescript-contrib%2Fpurescript-argonaut-generic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purescript-contrib%2Fpurescript-argonaut-generic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purescript-contrib%2Fpurescript-argonaut-generic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/purescript-contrib","download_url":"https://codeload.github.com/purescript-contrib/purescript-argonaut-generic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242635336,"owners_count":20161437,"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-03-09T02:36:36.443Z","updated_at":"2025-10-19T17:51:50.582Z","avatar_url":"https://github.com/purescript-contrib.png","language":"PureScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Argonaut Generic\n\n[![CI](https://github.com/purescript-contrib/purescript-argonaut-generic/workflows/CI/badge.svg?branch=main)](https://github.com/purescript-contrib/purescript-argonaut-generic/actions?query=workflow%3ACI+branch%3Amain)\n[![Release](http://img.shields.io/github/release/purescript-contrib/purescript-argonaut-generic.svg)](https://github.com/purescript-contrib/purescript-argonaut-generic/releases)\n[![Pursuit](http://pursuit.purescript.org/packages/purescript-argonaut-generic/badge)](http://pursuit.purescript.org/packages/purescript-argonaut-generic)\n\nThis package provides `genericEncodeJson` and `genericDecodeJson` functions for any data types that have a `Generic.Rep` instance, which can be used to encode or decode `Json` values or to implement `EncodeJson` and `DecodeJson` instances for [`argonaut-codecs`](https://github.com/purescript-contrib/purescript-argonaut-codecs).\n\n## Installation\n\nInstall `argonaut-generic` with [Spago](https://github.com/purescript/spago):\n\n```sh\nspago install argonaut-generic\n```\n\n## Quick start\n\nWe can use functions from the `Data.Argonaut.Decode.Generic.Rep` and `Data.Argonaut.Encode.Generic.Rep` modules to automatically write instances of `DecodeJson` and `EncodeJson` for our data types. The below example defines a recursive sum type, derives `Generic`, and then uses this library to write its decoding and encoding instances:\n\n```purs\nimport Prelude\n\nimport Data.Argonaut.Decode.Class (class DecodeJson)\nimport Data.Argonaut.Decode.Generic.Rep (genericDecodeJson)\nimport Data.Argonaut.Encode.Class (class EncodeJson)\nimport Data.Argonaut.Encode.Generic.Rep (genericEncodeJson)\nimport Data.Either (Either(..))\nimport Data.Generic.Rep (class Generic)\n\ndata Example\n  = Either (Either String Example)\n  | Record { foo :: Int, bar :: String }\n  | Nested { foo :: { nested :: Int }, bar :: String }\n  | Product Int Int Example\n\n-- We first need to derive `Generic` for our type\nderive instance genericExample :: Generic Example _\n\n-- Necessary to eta-expand because the generic data type is recursive.\ninstance encodeJsonExample :: EncodeJson Example where\n  encodeJson a = genericEncodeJson a\n\ninstance decodeJson :: DecodeJson Example where\n  decodeJson a = genericDecodeJson a\n```\n\nYou may also be interested in other libraries in the Argonaut ecosystem:\n\n- [purescript-argonaut-core](https://github.com/purescript-contrib/purescript-argonaut-core) defines the `Json` type, along with basic parsing, printing, and folding functions\n- [purescript-argonaut-codecs](https://github.com/purescript-contrib/purescript-argonaut-codecs) provides codecs based on `EncodeJson` and `DecodeJson` type classes, along with instances for common data types and combinators for encoding and decoding `Json` values.\n- [purescript-argonaut-traversals](https://github.com/purescript-contrib/purescript-argonaut-traversals) provides prisms, traversals, and a zipper for working with nested `Json` structures.\n\n## Documentation\n\n`argonaut-generic` documentation is stored in a few places:\n\n1. Module documentation is [published on Pursuit](https://pursuit.purescript.org/packages/purescript-argonaut-generic).\n2. Written documentation is kept in [the docs directory](./docs).\n3. Usage examples can be found in [the test suite](./test).\n\nIf you get stuck, there are several ways to get help:\n\n- [Open an issue](https://github.com/purescript-contrib/purescript-argonaut-generic/issues) if you have encountered a bug or problem.\n- Ask general questions on the [PureScript Discourse](https://discourse.purescript.org) forum or the [PureScript Discord](https://purescript.org/chat) chat.\n\n## Contributing\n\nYou can contribute to `argonaut-generic` in several ways:\n\n1. If you encounter a problem or have a question, please [open an issue](https://github.com/purescript-contrib/purescript-argonaut-generic/issues). We'll do our best to work with you to resolve or answer it.\n\n2. If you would like to contribute code, tests, or documentation, please [read the contributor guide](./CONTRIBUTING.md). It's a short, helpful introduction to contributing to this library, including development instructions.\n\n3. If you have written a library, tutorial, guide, or other resource based on this package, please share it on the [PureScript Discourse](https://discourse.purescript.org)! Writing libraries and learning resources are a great way to help this library succeed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurescript-contrib%2Fpurescript-argonaut-generic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpurescript-contrib%2Fpurescript-argonaut-generic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurescript-contrib%2Fpurescript-argonaut-generic/lists"}