{"id":22899015,"url":"https://github.com/dzakh/rescript-json-schema","last_synced_at":"2025-05-07T23:08:14.734Z","repository":{"id":40520345,"uuid":"463662394","full_name":"DZakh/rescript-json-schema","owner":"DZakh","description":"📄 Typesafe JSON schema for ReScript","archived":false,"fork":false,"pushed_at":"2025-04-02T07:41:47.000Z","size":1452,"stargazers_count":29,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-07T23:08:06.583Z","etag":null,"topics":["ajv","json","json-schema","openapi","rescript","swagger","typesafe"],"latest_commit_sha":null,"homepage":"https://dzakh.github.io/rescript-json-schema/","language":"JavaScript","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/DZakh.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-02-25T20:08:48.000Z","updated_at":"2025-04-02T07:40:13.000Z","dependencies_parsed_at":"2023-11-29T10:30:43.143Z","dependency_job_id":"c7f885f4-23ba-435d-ad6c-47075a4744eb","html_url":"https://github.com/DZakh/rescript-json-schema","commit_stats":{"total_commits":119,"total_committers":1,"mean_commits":119.0,"dds":0.0,"last_synced_commit":"9005594ee3ddd10af70d5543513324637b4ae978"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DZakh%2Frescript-json-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DZakh%2Frescript-json-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DZakh%2Frescript-json-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DZakh%2Frescript-json-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DZakh","download_url":"https://codeload.github.com/DZakh/rescript-json-schema/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252968118,"owners_count":21833251,"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":["ajv","json","json-schema","openapi","rescript","swagger","typesafe"],"created_at":"2024-12-14T00:35:40.238Z","updated_at":"2025-05-07T23:08:14.725Z","avatar_url":"https://github.com/DZakh.png","language":"JavaScript","readme":"[![CI](https://github.com/DZakh/rescript-json-schema/actions/workflows/ci.yml/badge.svg)](https://github.com/DZakh/rescript-json-schema/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/DZakh/rescript-json-schema/branch/main/graph/badge.svg?token=40G6YKKD6J)](https://codecov.io/gh/DZakh/rescript-json-schema)\n[![npm](https://img.shields.io/npm/dm/rescript-json-schema)](https://www.npmjs.com/package/rescript-json-schema)\n\n# ReScript JSON Schema 📄\n\nTypesafe JSON Schema for ReScript\n\n- Provides ReScript types to work with [JSON schema](https://json-schema.org/)\n- Converts [**rescript-schema**](https://github.com/DZakh/rescript-schema) into JSON schemas\n- Converts JSON schemas to [**rescript-schema**](https://github.com/DZakh/rescript-schema)\n\n## Install\n\n```sh\nnpm install rescript-json-schema rescript-schema\n```\n\nThen add `rescript-json-schema` and `rescript-schema` to `bs-dependencies` in your `rescript.json`:\n\n```diff\n{\n  ...\n+ \"bs-dependencies\": [\"rescript-json-schema\", \"rescript-schema\"]\n+ \"bsc-flags\": [\"-open RescriptSchema\"],\n}\n```\n\n## Create JSON schemas with type safety\n\nOne of the library's main features is the **rescript-schema**, which provides a way to describe the schema of a value. This schema contains meta information used for parsing, serializing, and generating JSON Schema. When working with the library, you will mostly interact with **rescript-schema** to define the schema of the values you are working with.\n\nFor example, if you have the following schema:\n\n```rescript\ntype rating =\n  | @as(\"G\") GeneralAudiences\n  | @as(\"PG\") ParentalGuidanceSuggested\n  | @as(\"PG13\") ParentalStronglyCautioned\n  | @as(\"R\") Restricted\ntype film = {\n  id: float,\n  title: string,\n  tags: array\u003cstring\u003e,\n  rating: rating,\n  deprecatedAgeRestriction: option\u003cint\u003e,\n}\n\nlet filmSchema = S.object(s =\u003e {\n  id: s.field(\"Id\", S.float),\n  title: s.field(\"Title\", S.string),\n  tags: s.fieldOr(\"Tags\", S.array(S.string), []),\n  rating: s.field(\n    \"Rating\",\n    S.union([\n      S.literal(GeneralAudiences),\n      S.literal(ParentalGuidanceSuggested),\n      S.literal(ParentalStronglyCautioned),\n      S.literal(Restricted),\n    ]),\n  ),\n  deprecatedAgeRestriction: s.field(\"Age\", S.option(S.int)-\u003eS.deprecate(\"Use rating instead\")),\n})\n```\n\nYou can use it to generate JSON Schema for the value it describes:\n\n```rescript\nJSONSchema.make(filmSchema)\n```\n\n```json\n{\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"Id\": { \"type\": \"number\" },\n    \"Title\": { \"type\": \"string\" },\n    \"Tags\": { \"items\": { \"type\": \"string\" }, \"type\": \"array\", \"default\": [] },\n    \"Rating\": {\n      \"enum\": [\"G\", \"PG\", \"PG13\", \"R\"]\n    },\n    \"Age\": {\n      \"type\": \"integer\",\n      \"deprecated\": true,\n      \"description\": \"Use rating instead\"\n    }\n  },\n  \"additionalProperties\": true,\n  \"required\": [\"Id\", \"Title\", \"Rating\"]\n}\n```\n\n## Create **rescript-schema** from JSON schema\n\n### Online\n\n![ReScript JSON Schema Online](assets/online-preview.png)\n\n[Just paste your JSON schemas here!](https://dzakh.github.io/rescript-json-schema/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdzakh%2Frescript-json-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdzakh%2Frescript-json-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdzakh%2Frescript-json-schema/lists"}