{"id":16717303,"url":"https://github.com/glennsl/rescript-json-combinators","last_synced_at":"2025-03-17T01:31:17.683Z","repository":{"id":45804879,"uuid":"514517718","full_name":"glennsl/rescript-json-combinators","owner":"glennsl","description":"Combinator library for JSON decoding and encoding.","archived":false,"fork":false,"pushed_at":"2024-02-13T13:22:30.000Z","size":54,"stargazers_count":45,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-13T21:31:48.560Z","etag":null,"topics":["combinators","decoder","decoding","encoder","encoding","json","rescript"],"latest_commit_sha":null,"homepage":"","language":"ReScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/glennsl.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}},"created_at":"2022-07-16T08:08:18.000Z","updated_at":"2024-08-18T19:31:51.000Z","dependencies_parsed_at":"2022-07-17T11:46:11.399Z","dependency_job_id":"f25fb890-8fc4-4b2d-8004-3eb253a58510","html_url":"https://github.com/glennsl/rescript-json-combinators","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"d2aa741737a4c5a69605e0d5041ddc8c5acb357b"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsl%2Frescript-json-combinators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsl%2Frescript-json-combinators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsl%2Frescript-json-combinators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glennsl%2Frescript-json-combinators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glennsl","download_url":"https://codeload.github.com/glennsl/rescript-json-combinators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243796730,"owners_count":20349264,"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":["combinators","decoder","decoding","encoder","encoding","json","rescript"],"created_at":"2024-10-12T21:31:22.807Z","updated_at":"2025-03-17T01:31:17.392Z","avatar_url":"https://github.com/glennsl.png","language":"ReScript","readme":"# rescript-json-combinators\nCombinator library for JSON decoding and encoding.\n\n[![npm](https://img.shields.io/npm/v/@glennsl/rescript-json-combinators.svg)](https://npmjs.org/@glennsl/rescript-json-combinators)\n[![Issues](https://img.shields.io/github/issues/glennsl/rescript-json-combinators.svg)](https://github.com/glennsl/rescript-json-combinators/issues)\n[![Last Commit](https://img.shields.io/github/last-commit/glennsl/rescript-json-combinators.svg)](https://github.com/glennsl/rescript-json-combinators/commits/master)\n\n\n## Example\n\n```rescript\ntype point = {\n  x: int,\n  y: int,\n}\n\ntype polyline = {\n  points: array\u003cpoint\u003e,\n  thickness: option\u003cint\u003e,\n}\n\nmodule Decode = {\n  open Json.Decode\n\n  let point = object(field =\u003e {\n    x: field.required(. \"x\", int),\n    y: field.required(. \"y\", int),\n  })\n\n  let polyline = object(field =\u003e {\n    points: field.required(. \"points\", array(point)),\n    thickness: field.optional(. \"thickness\", int),\n  })\n}\n\nlet data = `{\n  \"points\": [\n    { \"x\": 1, \"y\": -4 },\n    { \"x\": 5, \"y\": 8 }\n  ]\n}`\n\nlet _ = data-\u003eJs.Json.parseExn-\u003eJson.decode(Decode.polyline)-\u003eJs.log\n```\n\nSee [examples](https://github.com/glennsl/rescript-json-combinators/blob/master/examples/) for more.\n\n\n## Installation\n\n```sh\nnpm install --save @glennsl/rescript-json-combinators\n```\n\nThen add `@glennsl/rescript-json-combinators` to `bs-dependencies` in your `bsconfig.json`:\n\n```diff\n {\n   \"bs-dependencies\": [\n+    \"@glennsl/rescript-json-combinators\"\n   ]\n }\n```\n\n\nOptionally, add this to automatically open the library in order to use `Json.Encode` and `Json.Decode` directly:\n\n```diff\n {\n   \"bsc-flags\": [\n+    \"-open JsonCombinators\",\n   ]\n }\n```\n\n\n## Differences from bs-json\n\n`rescript-json-combinators` is the spriritual successor of `bs-json`. It was rewritten from scratch and not intended to be \nbackwards compatible. And while for the most part is does share the same design principles,there are also some notable differences:\n\n* Decoders have been made abstract. While the internal representation is still the same, a function that takes a `Js.Json.t`\nand returns either the decoded value or raises an exception, they can no longer be called directly. Instead they have to be run\nvia `Decode.decode`. This is in order to ensure that the `DecodeError` exceptions don't leak and returns a `result`\ninstead. Custom decoders can still be created with `Decode.custom`.\n\n* A new `object` decoder has been added, and while it's still possible to decode fields individually in a custom decoder, this\naddresses a couple ergonomic problems with that approach, such as distinguishing between a field missing and having the wrong\ntype, and the over-use and under-encapsulation of custom decoders.\n\n* Uncurrying and raw javascript is used in some places to improve performance. For the most part this isn't visible to the\nend user because decoders can no longer be called directly. There are a couple exceptions however, such as field decoders inside\nthe `object` deocder, and `map`.\n\n\n## Documentation\n\n### API\n\nFor the moment, please see the interface files:\n\n* [Json](https://github.com/glennsl/rescript-json-combinators/blob/master/src/Json.resi)\n* [Json.Encode](https://github.com/glennsl/rescript-json-combinators/blob/master/src/Json_Encode.resi)\n* [Json.Decode](https://github.com/glennsl/rescript-json-combinators/blob/master/src/Json_Decode.resi)\n\n\n## License\n\nThis work is dual-licensed under [LGPL 3.0](https://choosealicense.com/licenses/lgpl-3.0/) and \n[MPL 2.0](https://choosealicense.com/licenses/mpl-2.0/). You can choose between one of them if you use this work.\n\nPlease see [LICENSE.LGPL-3.0](https://github.com/glennsl/rescript-json-combinators/blob/master/LICENSE.LGPL-3.0) and \n[LICENSE.MPL-2.0](https://github.com/glennsl/rescript-json-combinators/blob/master/LICENSE.MPL-2.0) for the full text of each license.\n\n`SPDX-License-Identifier: LGPL-3.0 OR MPL-2.0`\n\n\n## Changes\n\n### 1.4.0\n- explicitly curried encode combinators to reduce breakage in rescript 11 uncurried mode\n- updated examples to rescript 11\n\n### 1.3.0\n- add `Decode.indirect` to help with decoding recursive data structures\n\n### 1.2.0\n- add `Decode.flatMap`\n\n### 1.1.0\n- recript v11-compatible formatting (#3)\n\n### 1.0.0\nInitial release\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglennsl%2Frescript-json-combinators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglennsl%2Frescript-json-combinators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglennsl%2Frescript-json-combinators/lists"}