{"id":13495617,"url":"https://github.com/nkrkv/jzon","last_synced_at":"2025-08-20T03:31:14.216Z","repository":{"id":43887495,"uuid":"337134580","full_name":"nkrkv/jzon","owner":"nkrkv","description":"ReScript library to encode and decode JSON data with type safety.","archived":false,"fork":false,"pushed_at":"2024-06-03T18:34:04.000Z","size":821,"stargazers_count":76,"open_issues_count":2,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-14T17:05:20.093Z","etag":null,"topics":["json","rescript"],"latest_commit_sha":null,"homepage":"https://nkrkv.github.io/jzon/","language":"ReScript","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/nkrkv.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2021-02-08T16:18:51.000Z","updated_at":"2024-09-03T14:35:36.000Z","dependencies_parsed_at":"2024-06-18T22:46:39.071Z","dependency_job_id":"bf0657eb-dff3-485f-b85e-e61fc9670996","html_url":"https://github.com/nkrkv/jzon","commit_stats":{"total_commits":85,"total_committers":1,"mean_commits":85.0,"dds":0.0,"last_synced_commit":"53c26a5225b6be2a2267f4a643abdab860d1d245"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkrkv%2Fjzon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkrkv%2Fjzon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkrkv%2Fjzon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nkrkv%2Fjzon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nkrkv","download_url":"https://codeload.github.com/nkrkv/jzon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230388131,"owners_count":18217755,"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":["json","rescript"],"created_at":"2024-07-31T19:01:36.430Z","updated_at":"2024-12-19T06:09:27.616Z","avatar_url":"https://github.com/nkrkv.png","language":"ReScript","funding_links":[],"categories":["ReScript"],"sub_categories":[],"readme":"# Jzon\n\nJzon is a library for ReScript to encode and decode JSON data with type safety.\n\n- 🎷 [Documentation](https://nkrkv.github.io/jzon/) 🎷\n- [Changelog](./CHANGELOG.md): MIT\n- [License](./LICENSE.md): MIT\n\n## Installation\n\n1. `yarn add rescript-jzon`\n2. Add `\"rescript-jzon\"` item to the `dependencies` key of `bsconfig.json`\n\n## Quick start\n\nImagine you have the following ReScript types to encode and decode:\n\n```rescript\ntype style = {\n  size: float,\n  color: string,\n}\n\ntype point = {\n  x: float,\n  y: float,\n  z: float,\n  style: option\u003cstyle\u003e,\n}\n```\n\nFirst, define their _codecs_:\n\n```rescript\nmodule Codecs = {\n  let style = Jzon.object2(\n    // Function to encode original object to linear tuple\n    ({size, color}) =\u003e (size, color),\n\n    // Function to decode linear tuple back to object\n    ((size, color)) =\u003e {size, color}-\u003eOk,\n\n    // Field names and codecs for the tuple elements\n    Jzon.field(\"size\", Jzon.float),\n    Jzon.field(\"color\", Jzon.string),\n  );\n\n  // Similar codec for another record type\n  let point = Jzon.object4(\n    ({x, y, z, style}) =\u003e (x, y, z, style),\n    ((x, y, z, style)) =\u003e {x, y, z, style}-\u003eOk,\n    Jzon.field(\"x\", Jzon.float),\n    Jzon.field(\"y\", Jzon.float),\n    // ... supports default values\n    Jzon.field(\"z\", Jzon.float)-\u003eJzon.default(0.0),\n    // ... may refer your other codecs\n    Jzon.field(\"style\", style)-\u003eJzon.optional,\n  )\n}\n```\n\nNext, convert between the ReScript types and `Js.Json.t` with:\n\n```rescript\nlet myPoint = {\n  x: 1.0,\n  y: 2.0,\n  z: 3.0,\n  style: Some({size: 4.0, color: \"#fd0\"}),\n}\n\nlet json = myPoint-\u003eJzon.encodeWith(Codecs.point)\n```\n\nand back with:\n\n```rescript\nlet myPoint = json-\u003eJzon.decodeWith(Codecs.point)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnkrkv%2Fjzon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnkrkv%2Fjzon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnkrkv%2Fjzon/lists"}