{"id":19115387,"url":"https://github.com/polytypic/schemation","last_synced_at":"2025-06-13T15:06:42.367Z","repository":{"id":65493363,"uuid":"49158825","full_name":"polytypic/schemation","owner":"polytypic","description":null,"archived":false,"fork":false,"pushed_at":"2017-07-11T07:20:59.000Z","size":42,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T20:43:15.048Z","etag":null,"topics":["json","schema","validation"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polytypic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-06T20:11:18.000Z","updated_at":"2018-01-29T13:44:20.000Z","dependencies_parsed_at":"2023-01-25T20:35:12.001Z","dependency_job_id":null,"html_url":"https://github.com/polytypic/schemation","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polytypic%2Fschemation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polytypic%2Fschemation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polytypic%2Fschemation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polytypic%2Fschemation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polytypic","download_url":"https://codeload.github.com/polytypic/schemation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249249880,"owners_count":21237804,"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","schema","validation"],"created_at":"2024-11-09T04:46:13.773Z","updated_at":"2025-04-19T00:32:44.689Z","avatar_url":"https://github.com/polytypic.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/schemation.svg)](http://badge.fury.io/js/schemation) [![Build Status](https://travis-ci.org/polytypic/schemation.svg?branch=master)](https://travis-ci.org/polytypic/schemation) [![](https://david-dm.org/polytypic/schemation.svg)](https://david-dm.org/polytypic/schemation) [![](https://david-dm.org/polytypic/schemation/dev-status.svg)](https://david-dm.org/polytypic/schemation?type=dev)\n\n## Schema grammar\n\n```javascript\nimport {any, boolean, number, string} from \"schemation\"\nimport {and, not, or}                 from \"schemation\"\nimport {where}                        from \"schemation\"\nimport {optional}                     from \"schemation\"\nimport {lazy}                         from \"schemation\"\n```\n\n```jsx\n   \u003cschema\u003e ::= \u003cclass\u003e\n              | \u003clazy\u003e\n              | \u003clogical\u003e\n              | \u003cpredicate\u003e\n              | \u003cshape\u003e\n\n    \u003cclass\u003e ::= any\n              | boolean\n              | number\n              | string\n\n     \u003clazy\u003e ::= lazy( () =\u003e \u003cschema\u003e )\n\n  \u003clogical\u003e ::= and( \u003cschema\u003e, ... )\n              | not( \u003cschema\u003e )\n              |  or( \u003cschema\u003e, ... )\n\n\u003cpredicate\u003e ::= /.../\n              | where( \u003cunary-predicate\u003e )\n\n    \u003cshape\u003e ::= false | true\n              | \"...\"\n              | \u003cnumber\u003e\n              | [ \u003cschema\u003e ]\n              | null\n              | { \u003cproperty\u003e, ... }\n\n \u003cproperty\u003e ::= \"...\":           \u003cschema\u003e\n              | \"...\": optional( \u003cschema\u003e )\n```\n\n## Entry points\n\n```javascript\nimport {matches, tryMatch, validate} from \"schemation\"\n```\n\n```javascript\nmatches(schema)(json)\n  =\u003e true\n   | false\n```\n\n```javascript\ntryMatch(schema, onMatch, onMismatch)(json)\n  =\u003e onMatch(json)\n   | onMismatch(mismatch)\n```\n\n```javascript\nvalidate(schema)(json)\n  =\u003e json\n   | throw new Error(mismatch)\n```\n\n## Mismatches\n\n```javascript\nimport {Mismatch, MismatchAt, Mismatches} from \"schemation\"\n```\n\n```javascript\nmismatch ::= Mismatch {value}\n           | MismatchAt {mismatch, index}\n           | Mismatches {mismatches}\n```\n\n```javascript\nmismatch.toString()\n```\n\n## Extending\n\nFor example, given\n\n```javascript\nconst empty = where(x =\u003e x.length === 0)\n```\n\nthe expression\n\n```javascript\nand([any], not(empty))\n```\n\nmatches any non-empty array.\n\n## Example\n\n```javascript\nconst SetOfProducts = [\n  {\n    id: number,\n    name: string,\n    price: and(number, where(x =\u003e 0 \u003c x)),\n    tags: optional(and([string], not(empty))),\n    dimensions: optional({\n      length: number,\n      width: number,\n      height: number\n    }),\n    warehouselocation: optional({\n      latitude: number,\n      longitude: number\n    })\n  }\n]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolytypic%2Fschemation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolytypic%2Fschemation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolytypic%2Fschemation/lists"}