{"id":15980910,"url":"https://github.com/vitalets/json-micro-schema","last_synced_at":"2026-01-19T08:31:50.536Z","repository":{"id":42965678,"uuid":"223897956","full_name":"vitalets/json-micro-schema","owner":"vitalets","description":"Minimal JSON schema validation format","archived":false,"fork":false,"pushed_at":"2023-03-02T06:33:49.000Z","size":31,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-13T18:18:41.245Z","etag":null,"topics":["json","json-schema","json-validation"],"latest_commit_sha":null,"homepage":null,"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/vitalets.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},"funding":{"github":["vitalets"]}},"created_at":"2019-11-25T08:26:37.000Z","updated_at":"2022-12-20T12:42:54.000Z","dependencies_parsed_at":"2024-06-13T06:01:12.407Z","dependency_job_id":null,"html_url":"https://github.com/vitalets/json-micro-schema","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fjson-micro-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fjson-micro-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fjson-micro-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitalets%2Fjson-micro-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vitalets","download_url":"https://codeload.github.com/vitalets/json-micro-schema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247682575,"owners_count":20978705,"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","json-schema","json-validation"],"created_at":"2024-10-08T00:23:31.962Z","updated_at":"2026-01-19T08:31:50.505Z","avatar_url":"https://github.com/vitalets.png","language":"JavaScript","readme":"# JSON micro schema\n\nMinimal JSON schema validation format.\n\n## Motivation\nAlthough [JSON Schema](https://json-schema.org/) is old and mature project\nit looks too complex for simple JSON validation purpose.\nThis spec is a very simple format for the most common cases.\n\n## Contents\n\n\u003c!-- toc --\u003e\n\n- [Principles](#principles)\n- [Example](#example)\n- [Validators](#validators)\n  * [$type](#type)\n  * [$required](#required)\n  * [$maxLength](#maxlength)\n  * [$minLength](#minlength)\n  * [$values](#values)\n  * [$unknownKeys](#unknownkeys)\n  * [$item](#item)\n  * [$defaults](#defaults)\n- [Shortcuts](#shortcuts)\n  * [Primitives](#primitives)\n  * [Arrays](#arrays)\n- [Custom validators](#custom-validators)\n- [Implementations](#implementations)\n  * [JavaScript](#javascript)\n- [License](#license)\n\n\u003c!-- tocstop --\u003e\n\n## Principles\n* All keywords started with `$`.\n* Built-in validators cover most common cases.\n* Custom validators can be easily added.\n* No code-generation.\n\n## Example\nSchema:\n```json\n{\n  \"productId\": {\n    \"$type\": \"number\",\n    \"$required\": true\n  },\n  \"productName\": {\n    \"$type\": \"string\",\n    \"$required\": true,\n    \"$maxLength\": 255\n  },\n  \"tags\": [{\n    \"$type\": \"string\"\n  }]\n}\n```\nValid object:\n```json\n{\n  \"productId\": 1,\n  \"productName\": \"iphone 11\",\n  \"tags\": [ \"mobile\", \"phone\" ]\n}\n```\n\nInvalid object:\n```json\n{\n  \"productId\": \"1\",\n  \"productName\": null,\n  \"tags\": [ 42 ]\n}\n```\n\nValidation errors:\n```json\n[\n  {\n    \"validator\": \"$type\",\n    \"path\": \"productId\",\n    \"expectedType\": \"number\",\n    \"actualType\": \"string\"\n  },\n  {\n    \"validator\": \"$required\",\n    \"path\": \"productName\"\n  },\n  {\n    \"validator\": \"$type\",\n    \"path\": \"tags.0\",\n    \"expectedType\": \"string\",\n    \"actualType\": \"number\"\n  }\n]\n```\n\n## Validators\n\n### $type\n* `string` Validates type of value. Can be one of:\n  * `\"string\"`\n  * `\"number\"`\n  * `\"boolean\"`\n  * `\"array\"`\n\nExample of schema:\n```json\n{\n  \"productName\": {\n    \"$type\": \"string\"\n  }\n}\n```\n\nValid object:\n```json\n{\n  \"productName\": \"iphone 11\"\n}\n```\n\nInvalid object:\n```json\n{\n  \"productName\": 42\n}\n```\n\nValidation error:\n```json\n{\n  \"validator\": \"$type\",\n  \"path\": \"productName\",\n  \"expectedType\": \"string\",\n  \"actualType\": \"number\"\n}\n```\n\n### $required\n* `boolean` Validates that property exists and not `null|undefined`.\n\nExample of schema:\n```json\n{\n  \"productName\": {\n    \"$required\": true\n  }\n}\n```\n\nValid object:\n```json\n{\n  \"productName\": \"iphone 11\"\n}\n```\n\nInvalid object:\n```json\n{\n  \"productName\": null\n}\n```\n\nValidation error:\n```json\n{\n  \"validator\": \"$required\",\n  \"path\": \"productName\"\n}\n```\n\n### $maxLength\n* `number` Validates that property has length less or equal provided value.\n  Applied to `string` or `array`.\n\nExample of schema:\n```json\n{\n  \"productName\": {\n    \"$type\": \"string\",\n    \"$maxLength\": 10\n  }\n}\n```\n\nValid object:\n```json\n{\n  \"productName\": \"iphone 11\"\n}\n```\n\nInvalid object:\n```json\n{\n  \"productName\": \"very long product name\"\n}\n```\n\nValidation error:\n```json\n{\n  \"validator\": \"$maxLength\",\n  \"path\": \"productName\",\n  \"maxLength\": 10,\n  \"length\": 22\n}\n```\n\n### $minLength\n* `number` Validates that property has length more or equal provided value.\n  Applied to `string` or `array`.\n\nExample of schema:\n```json\n{\n  \"productName\": {\n    \"$type\": \"string\",\n    \"$minLength\": 2\n  }\n}\n```\n\nValid object:\n```json\n{\n  \"productName\": \"iphone 11\"\n}\n```\n\nInvalid object:\n```json\n{\n  \"productName\": \"a\"\n}\n```\n\nValidation error:\n```json\n{\n  \"validator\": \"$minLength\",\n  \"path\": \"productName\",\n  \"minLength\": 2,\n  \"length\": 1\n}\n```\n\n### $values\n* `array` Validates that property has one of provided values.\n\nExample of schema:\n```json\n{\n  \"productName\": {\n    \"$type\": \"string\",\n    \"$values\": [\"iphone\", \"android\"]\n  }\n}\n```\n\nValid object:\n```json\n{\n  \"productName\": \"iphone\"\n}\n```\n\nInvalid object:\n```json\n{\n  \"productName\": \"ipad\"\n}\n```\n\nValidation error:\n```json\n{\n  \"validator\": \"$values\",\n  \"path\": \"productName\",\n  \"values\": [\"iphone\", \"android\"],\n  \"value\": \"ipad\"\n}\n```\n\n### $unknownKeys\n* `boolean` Allows object to have keys not declared in schema.\n\nExample of schema:\n```json\n{\n  \"product\": {\n    \"$unknownKeys\": false,\n    \"name\": {\n      \"$type\": \"string\"\n    }\n  }\n}\n```\n\nValid object:\n```json\n{\n  \"product\": {\n     \"name\": \"iphone\"\n  }\n}\n```\n\nInvalid object:\n```json\n{\n  \"product\": {\n     \"name\": \"iphone\",\n     \"model\": \"iphone 11\"\n  }\n}\n```\n\nValidation error:\n```json\n{\n  \"validator\": \"$unknownKeys\",\n  \"path\": \"product.model\"\n}\n```\n\n### $item\n* `object` Declares schema for array items. Applied only to `$type: \"array\"`.\n\nExample of schema:\n```json\n{\n  \"tags\": {\n    \"$type\": \"array\",\n    \"$item\": {\n      \"$type\": \"string\"\n    }\n  }\n}\n```\n\nValid object:\n```json\n{\n  \"tags\": [ \"mobile\", \"phone\" ]\n}\n```\n\nInvalid object:\n```json\n{\n  \"tags\": [ 42 ]\n}\n```\n\nValidation error:\n```json\n{\n  \"validator\": \"$type\",\n  \"path\": \"tags.0\",\n  \"expectedType\": \"string\",\n  \"actualType\": \"number\"\n}\n```\n\n### $defaults\n* `object` Declares schema that will be merged to current and all nested schemas.\n\nExample of schema:\n```json\n{\n  \"$defaults\": {\n    \"$required\": true\n  },\n  \"productId\": {\n    \"$type\": \"number\"\n  },\n  \"productName\": {\n    \"$type\": \"string\"\n  }\n}\n```\n\nValid object:\n```json\n{\n  \"productId\": 1,\n  \"productName\": \"iphone 11\"\n}\n```\n\nInvalid object:\n```json\n{\n  \"foo\": \"bar\"\n}\n```\n\nValidation errors:\n```json\n[\n  {\n    \"validator\": \"$required\",\n    \"path\": \"productId\"\n  },\n  {\n    \"validator\": \"$required\",\n    \"path\": \"productName\"\n  }\n]\n```\n\n## Shortcuts\n### Primitives\nYou can declare any prop as just a value:\n```json\n{\n  \"productType\": \"phone\"\n}\n```\nIt is automatically expanded to the following schema:\n```json\n{\n  \"productType\": {\n    \"$type\": \"string\",\n    \"$required\": true,\n    \"$values\": [\"phone\"]\n  }\n}\n```\n\n### Arrays\nArrays can be declared in two ways:\n1. full syntax using `$item` validator:\n    ```json\n    {\n      \"tags\": {\n        \"$type\": \"array\",\n        \"$item\": {\n          \"$type\": \"string\"\n        }\n      }\n    }\n    ```\n2. shortcut syntax using `[]` with single element:\n    ```json\n    {\n      \"tags\": [{\n        \"$type\": \"string\"\n      }]\n    }\n    ```\n\nBoth variants are identical.\n\n## Custom validators\nYou can declare any custom validators for your needs.\nThe only rule is that it should start with `$` and don't conflict with built-in validators.\nExample of custom `$myRegexpValidator`:\n```json\n{\n  \"productId\": {\n    \"$type\": \"string\",\n    \"$myRegexpValidator\": \"[a-z0-9]+\"\n  }\n}\n```\nTechnical implementation of custom validator depends on library and programming language you are using.\n\n## Implementations\n\n### JavaScript\n  * [@vitalets/micro-schema](https://github.com/vitalets/micro-schema)\n\n## License\nMIT @ [Vitaliy Potapov](https://github.com/vitalets)\n","funding_links":["https://github.com/sponsors/vitalets"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitalets%2Fjson-micro-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitalets%2Fjson-micro-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitalets%2Fjson-micro-schema/lists"}