{"id":13726732,"url":"https://github.com/mlms13/bs-decode","last_synced_at":"2026-03-12T14:39:24.929Z","repository":{"id":33023802,"uuid":"147429778","full_name":"mlms13/bs-decode","owner":"mlms13","description":"Type-safe JSON decoding for ReasonML and OCaml","archived":false,"fork":false,"pushed_at":"2024-01-22T20:34:06.000Z","size":2072,"stargazers_count":103,"open_issues_count":15,"forks_count":18,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-10T00:17:43.169Z","etag":null,"topics":["bucklescript","decoding","json","json-decoding","json-values","reasonml"],"latest_commit_sha":null,"homepage":"https://mlms13.github.io/bs-decode/docs/what-and-why","language":"Reason","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/mlms13.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-09-04T22:55:54.000Z","updated_at":"2024-06-04T21:29:35.000Z","dependencies_parsed_at":"2023-11-30T18:29:44.733Z","dependency_job_id":"c17c1649-ece7-46a7-9b03-45cf6b98d0f5","html_url":"https://github.com/mlms13/bs-decode","commit_stats":{"total_commits":196,"total_committers":14,"mean_commits":14.0,"dds":0.1785714285714286,"last_synced_commit":"2888c284a46b1e136c21ccb09d8772c7135abe21"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlms13%2Fbs-decode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlms13%2Fbs-decode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlms13%2Fbs-decode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlms13%2Fbs-decode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlms13","download_url":"https://codeload.github.com/mlms13/bs-decode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131318,"owners_count":21052820,"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":["bucklescript","decoding","json","json-decoding","json-values","reasonml"],"created_at":"2024-08-03T01:03:18.328Z","updated_at":"2026-03-12T14:39:19.899Z","avatar_url":"https://github.com/mlms13.png","language":"Reason","readme":"# bs-decode\n\n[![build status](https://img.shields.io/circleci/build/github/mlms13/bs-decode.svg?style=flat-square)](https://circleci.com/gh/mlms13/bs-decode)\n[![test coverage](https://img.shields.io/coveralls/github/mlms13/bs-decode.svg?style=flat-square)](https://coveralls.io/github/mlms13/bs-decode)\n[![npm version](https://img.shields.io/npm/v/bs-decode.svg?style=flat-square)](https://www.npmjs.com/package/bs-decode)\n[![license](https://img.shields.io/github/license/mlms13/bs-decode.svg?style=flat-square)](https://github.com/mlms13/bs-decode/blob/master/LICENSE)\n\n\u003e **Note**\n\u003e\n\u003e bs-decode has been stable and used in production for several years, so a v1 release makes sense. This is the final release that will be compatible with BuckleScript as we turn our attention to the newer OCaml features available in Melange.\n\n[Read the Documentation](https://mlms13.github.io/bs-decode/docs/)\n\nDecode JSON values into structured ReasonML and OCaml types. Inspired by Elm's [Json.Decode](https://package.elm-lang.org/packages/elm-lang/core/5.1.1/Json-Decode) and the [Decode Pipeline](https://package.elm-lang.org/packages/NoRedInk/elm-decode-pipeline/3.0.1/Json-Decode-Pipeline), `bs-decode` is an alternative to [bs-json](https://github.com/glennsl/bs-json) that focuses on structured, type-safe error handling, rather than exceptions. Additionally, `bs-decode` collects up _everything_ that went wrong while parsing the JSON, rather than failing on the first error.\n\n## Installation\n\n**Install via npm:**\n\n`npm install --save bs-decode relude bs-bastet`\n\n**Update your bsconfig.json**\n\n```\n\"bs-dependencies\": [\n  \"bs-bastet\",\n  \"bs-decode\",\n  \"relude\"\n],\n```\n\n\n## Usage\n\nThe following is available to give you an idea of how the library works, but [the complete documentation](https://mlms13.github.io/bs-decode/docs/simple-example) will probably be more useful if you want to write your own decoders.\n\n```reason\n// imagine you have a `user` type and `make` function to construct one\ntype user = {\n  name: string,\n  age: int,\n  isAdmin: bool,\n  lastLogin: option(Js.Date.t)\n};\n\nlet make = (name, age, isAdmin, lastLogin) =\u003e\n  { name, age, isAdmin, lastLogin };\n\n/**\n * Given a JSON value that looks like:\n * { \"name\": \"Alice\", \"age\": 44, \"roles\": [\"admin\"] }\n *\n * you can write a function to convert this JSON into a value of type `user`\n */\nmodule Decode = Decode.AsResult.OfParseError; // module alias for brevity\n\nlet decode = json =\u003e\n  Decode.Pipeline.(\n    succeed(make)\n    |\u003e field(\"name\", string)\n    |\u003e field(\"age\", intFromNumber)\n    |\u003e field(\"roles\", list(string) |\u003e map(List.contains(\"admin\")))\n    |\u003e optionalField(\"lastLogin\", date)\n    |\u003e run(json)\n  );\n\nlet myUser = decode(json); /* Ok({ name: \"Alice\", ...}) */\n```\n\n## Contributing\n\nAll contributions are welcome! This obviously includes code changes and documentation improvements ([see CONTRIBUTING](https://github.com/mlms13/bs-decode/blob/master/CONTRIBUTING.md)), but we also appreciate any feedback you want to provide (in the form of [Github issues](https://github.com/mlms13/bs-decode/issues)) about concepts that are confusing or poorly explained in [the docs](https://mlms13.github.io/bs-decode/docs/what-and-why).\n\n## License\n\nReleased under the [MIT license](https://github.com/mlms13/bs-decode/blob/master/LICENSE).\n","funding_links":[],"categories":["Reason"],"sub_categories":["Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlms13%2Fbs-decode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlms13%2Fbs-decode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlms13%2Fbs-decode/lists"}