{"id":16726895,"url":"https://github.com/lpil/decode","last_synced_at":"2025-03-15T15:43:45.702Z","repository":{"id":246709944,"uuid":"821941260","full_name":"lpil/decode","owner":"lpil","description":"Ergonomic dynamic decoders for Gleam!","archived":false,"fork":false,"pushed_at":"2024-12-19T12:52:22.000Z","size":81,"stargazers_count":76,"open_issues_count":0,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-15T12:54:46.710Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Gleam","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lpil.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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":"2024-06-29T21:34:49.000Z","updated_at":"2025-03-13T18:35:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"6b2ab480-b06e-4512-a315-d7718b8fd970","html_url":"https://github.com/lpil/decode","commit_stats":null,"previous_names":["lpil/decode"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpil%2Fdecode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpil%2Fdecode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpil%2Fdecode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lpil%2Fdecode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lpil","download_url":"https://codeload.github.com/lpil/decode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243753990,"owners_count":20342537,"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-10-12T22:55:03.544Z","updated_at":"2025-03-15T15:43:45.678Z","avatar_url":"https://github.com/lpil.png","language":"Gleam","funding_links":[],"categories":[],"sub_categories":[],"readme":"# decode\n\nErgonomic dynamic decoders for Gleam!\n\n[![Package Version](https://img.shields.io/hexpm/v/decode)](https://hex.pm/packages/decode)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/decode/)\n\n```sh\ngleam add decode\n```\n```gleam\nimport decode/zero as decode\nimport gleam/dynamic.{type Dynamic}\n\n\npub type User {\n  User(name: String, email: String, is_admin: Bool)\n}\n\n/// Decode data of this shape into a `User` record.\n///\n/// {\n///   \"name\" -\u003e \"Lucy\",\n///   \"email\" -\u003e \"lucy@example.com\",\n///   \"is-admin\" -\u003e true\n/// }\n///\npub fn run(data: Dynamic) {\n  let decoder = {\n    use name \u003c- decode.field(\"name\", decode.string)\n    use email \u003c- decode.field(\"email\", decode.string)\n    use is_admin \u003c- decode.field(\"is-admin\", decode.bool)\n    decode.success(User(name:, email:, is_admin:))\n  }\n\n  decode.run(data, decoder)\n}\n```\nOr, alternatively:\n```gleam\nimport decode\nimport gleam/dynamic.{type Dynamic}\n\npub type User {\n  User(name: String, email: String, is_admin: Bool)\n}\n\n/// Decode data of this shape into a `User` record.\n///\n/// {\n///   \"name\" -\u003e \"Lucy\",\n///   \"email\" -\u003e \"lucy@example.com\",\n///   \"is-admin\" -\u003e true\n/// }\n///\npub fn run(data: Dynamic) {\n  let decoder =\n    decode.into({\n      use name \u003c- decode.parameter\n      use email \u003c- decode.parameter\n      use is_admin \u003c- decode.parameter\n      User(name, email, is_admin)\n    })\n    |\u003e decode.field(\"name\", decode.string)\n    |\u003e decode.field(\"email\", decode.string)\n    |\u003e decode.field(\"is-admin\", decode.bool)\n\n  decoder\n  |\u003e decode.from(data)\n}\n```\nFor more documentation and examples view \u003chttps://hexdocs.pm/decode\u003e.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flpil%2Fdecode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flpil%2Fdecode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flpil%2Fdecode/lists"}