{"id":20978962,"url":"https://github.com/ryparker/schematized","last_synced_at":"2025-05-14T14:32:57.082Z","repository":{"id":37829891,"uuid":"270061654","full_name":"ryparker/schematized","owner":"ryparker","description":"Turn objects into JSON schemas! The more examples you provide, the better your schema will be.","archived":false,"fork":false,"pushed_at":"2023-01-06T09:16:40.000Z","size":1333,"stargazers_count":6,"open_issues_count":19,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-05-13T05:03:22.707Z","etag":null,"topics":["build","convert","data","datatypes","generate","genson","json","json-schemas","object","produce","schema","turn-objects","type","types","validation"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/ryparker.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-06T18:02:33.000Z","updated_at":"2024-07-29T14:34:02.000Z","dependencies_parsed_at":"2023-02-05T18:46:16.436Z","dependency_job_id":null,"html_url":"https://github.com/ryparker/schematized","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryparker%2Fschematized","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryparker%2Fschematized/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryparker%2Fschematized/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryparker%2Fschematized/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryparker","download_url":"https://codeload.github.com/ryparker/schematized/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254160648,"owners_count":22024574,"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":["build","convert","data","datatypes","generate","genson","json","json-schemas","object","produce","schema","turn-objects","type","types","validation"],"created_at":"2024-11-19T05:10:20.089Z","updated_at":"2025-05-14T14:32:56.724Z","avatar_url":"https://github.com/ryparker.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Schematized\n\n[![npm version](https://badge.fury.io/js/schematized.svg)](https://badge.fury.io/js/schematized)\n![Build-Test-Publish](https://github.com/ryparker/JSON-Schema-Builder/workflows/Build-Test-Publish/badge.svg)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)\n\nTurn objects into JSON schemas! The more examples you provide, the better your schema will be.\n\nA Node port of the Python module [GenSON](https://github.com/wolverdude/GenSON) but with more inferred constraints.\n\n**Example use case:** Generate JSON schemas using your API tests, then use the schemas to validate. To keep up to date, Write a test that compares your current schema with the generated schema. Then when your API changes, just update the tests with the newly generated schemas and move on with your day.\n\n---\n\n- [Schematized](#schematized)\n  - [:rocket: Quick start](#-quick-start)\n    - [Schema from the single example](#schema-from-the-single-example)\n    - [Schema from the two examples](#schema-from-the-two-examples)\n    - [Schema from the two examples and the schema](#schema-from-the-two-examples-and-the-schema)\n  - [:books: API](#-api)\n  - [:dart: Supported Schema Features](#-supported-schema-features)\n    - [Types](#types)\n    - [Typeless](#typeless)\n    - [String](#string)\n      - [Supported String formats](#supported-string-formats)\n    - [Number](#number)\n    - [Object](#object)\n    - [Array](#array)\n\n---\n\n## :rocket: Quick start\n\n1. **Add dependency**\n\n```shell\nyarn add schematized\n```\n\n2. **Basic usage** : [See output](#schema-from-the-single-example)\n\n```ts\nimport SchemaBuilder from 'schematized' // Typescript \u0026 ESM\nconst { default: SchemaBuilder } = require('schematized') // CommonJS\n\nconst builder = new SchemaBuilder()\n\n// Consume JSON\nbuilder.addObject({\n  token: '74aea1a53d68b77e4f1f55fa90a7eb81',\n  role: ['Basic'],\n})\n\n// Produce JSON Schemas!\nconst schema = builder.toPrettySchema()\n```\n\n3. **Improve the schema with examples** : [See output](#schema-from-the-two-examples)\n\n```ts\n...\n\nbuilder.addObject({\n  token: 'Bearer 6498d9afc96d1d8d881a2b7ded4f9290',\n  role: [\n    'Admin',\n    'Basic',\n    'Publisher'\n  ]\n})\n```\n\n4. **Improve the schema with existing schemas** : [See output](#schema-from-the-two-examples-and-the-schema)\n\n```ts\n...\n\nbuilder.addSchema({\n  title: '/user server response',\n  description: '/user server response'\n})\n```\n\n---\n\n### Schema from the single example\n\n```JSON\n{\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"token\": {\n      \"type\": \"string\",\n      \"maxLength\": 32,\n      \"minLength\": 32\n    },\n    \"role\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"string\",\n        \"maxLength\": 5,\n        \"minLength\": 5\n      }\n    }\n  },\n  \"required\": [\n    \"role\",\n    \"token\"\n  ],\n  \"additionalProperties\": false,\n  \"maxProperties\": 2,\n  \"minProperties\": 2\n}\n```\n\n### Schema from the two examples\n\n```JSON\n{\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"token\": {\n      \"type\": \"string\",\n      \"maxLength\": 39,\n      \"minLength\": 32\n    },\n    \"role\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"string\",\n        \"maxLength\": 9,\n        \"minLength\": 5\n      }\n    }\n  },\n  \"required\": [\n    \"role\",\n    \"token\"\n  ],\n  \"additionalProperties\": false,\n  \"maxProperties\": 2,\n  \"minProperties\": 2\n}\n```\n\n### Schema from the two examples and the schema\n\n```JSON\n{\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"title\": \"/user server response\",\n  \"description\": \"/user server response\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"token\": {\n      \"type\": \"string\",\n      \"maxLength\": 39,\n      \"minLength\": 32\n    },\n    \"role\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"string\",\n        \"maxLength\": 9,\n        \"minLength\": 5\n      }\n    }\n  },\n  \"required\": [\n    \"role\",\n    \"token\"\n  ],\n  \"additionalProperties\": false,\n  \"maxProperties\": 2,\n  \"minProperties\": 2\n}\n```\n\n---\n\n## :books: API\n\n| Method                | Definition                                      | Parameter         |\n| --------------------- | ----------------------------------------------- | ----------------- |\n| `.addObject($object)` | Add an example to improve the generated schema. | Valid JSON object |\n| `.addSchema($schema)` | Add schemas to improve the generated schema.    | Valid JSON Schema |\n| `.toSchema()`         | Generate the schema.                            | None              |\n| `.toPrettySchema()`   | Generate the schema and pretty print.           | None              |\n\n## :dart: Supported Schema Features\n\nVisit the [official JSON Schema site](https://json-schema.org/understanding-json-schema/reference/index.html) for specification details.\n\n### Types\n\n| Type    | Supported |\n| ------- | --------- |\n| String  | Yes       |\n| Number  | Yes       |\n| Integer | Never     |\n| Object  | Yes       |\n| Array   | Yes       |\n| Tuple   | Not yet   |\n| Boolean | Yes       |\n| Null    | Yes       |\n\n### Typeless\n\n| Constraint   | addSchema() | addObject() |\n| ------------ | ----------- | ----------- |\n| title        | Yes         | Never       |\n| description  | Yes         | Never       |\n| \\$comment    | Yes         | Never       |\n| default      | Not yet     | Not yet     |\n| examples     | Not yet     | Not yet     |\n| enum         | Not yet     | Not yet     |\n| const        | Not yet     | Not yet     |\n| anyOf        | Yes         | Yes         |\n| allOf        | Not yet     | Not yet     |\n| oneOf        | Not yet     | Not yet     |\n| not          | Not yet     | Not yet     |\n| if/then/else | Not yet     | Not yet     |\n\n### String\n\n| Constraint       | addSchema() | addObject() |\n| ---------------- | ----------- | ----------- |\n| maxLength        | Yes         | Yes         |\n| minLength        | Yes         | Yes         |\n| format           | Yes         | Yes         |\n| pattern          | Not yet     | Not yet     |\n| contentMediaType | Not yet     | Not yet     |\n| contentEncoding  | Not yet     | Not yet     |\n\n#### Supported String formats\n\n| Format                | Supported? |\n| --------------------- | ---------- |\n| date-time             | Yes        |\n| date                  | Yes        |\n| time                  | Yes        |\n| email                 | Yes        |\n| hostname              | Not yet    |\n| idn-hostname          | Not yet    |\n| ipv4                  | Yes        |\n| ipv6                  | Yes        |\n| uri                   | Yes        |\n| uri-reference         | Not yet    |\n| url                   | Yes        |\n| uuid                  | Yes        |\n| iri                   | Not yet    |\n| iri-reference         | Not yet    |\n| uri-template          | Not yet    |\n| json-pointer          | Not yet    |\n| relative-json-pointer | Not yet    |\n| regex                 | Not yet    |\n\n### Number\n\n| Constraint       | addSchema() | addObject() |\n| ---------------- | ----------- | ----------- |\n| maximum          | Yes         | Yes         |\n| minimum          | Yes         | Yes         |\n| exclusiveMaximum | Not yet     | Not yet     |\n| exclusiveMinimum | Not yet     | Not yet     |\n| multiple         | Not yet     | Not yet     |\n\n### Object\n\n| Constraint           | addSchema() | addObject() |\n| -------------------- | ----------- | ----------- |\n| propertyPatterns     | Yes         | Yes         |\n| additionalProperties | Yes         | Yes         |\n| required             | Yes         | Yes         |\n| maxProperties        | Yes         | Yes         |\n| minProperties        | Yes         | Yes         |\n\n### Array\n\n| Constraint  | addSchema() | addObject() |\n| ----------- | ----------- | ----------- |\n| maxItems    | Not yet     | Not yet     |\n| minItems    | Not yet     | Not yet     |\n| uniqueItems | Not yet     | Not yet     |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryparker%2Fschematized","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryparker%2Fschematized","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryparker%2Fschematized/lists"}