{"id":22645502,"url":"https://github.com/akmjenkins/json-rules-engine-schema-operator","last_synced_at":"2026-05-14T23:02:41.536Z","repository":{"id":57285157,"uuid":"417314139","full_name":"akmjenkins/json-rules-engine-schema-operator","owner":"akmjenkins","description":"An operator for json-rules-engine to validate against a json schema","archived":false,"fork":false,"pushed_at":"2021-11-10T17:51:31.000Z","size":75,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-03T22:39:59.588Z","etag":null,"topics":["json-rules-engine","json-schema","rules-engine"],"latest_commit_sha":null,"homepage":"","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/akmjenkins.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}},"created_at":"2021-10-14T23:47:09.000Z","updated_at":"2022-09-29T22:21:29.000Z","dependencies_parsed_at":"2022-09-19T23:21:36.256Z","dependency_job_id":null,"html_url":"https://github.com/akmjenkins/json-rules-engine-schema-operator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akmjenkins%2Fjson-rules-engine-schema-operator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akmjenkins%2Fjson-rules-engine-schema-operator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akmjenkins%2Fjson-rules-engine-schema-operator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akmjenkins%2Fjson-rules-engine-schema-operator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akmjenkins","download_url":"https://codeload.github.com/akmjenkins/json-rules-engine-schema-operator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246145601,"owners_count":20730593,"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-rules-engine","json-schema","rules-engine"],"created_at":"2024-12-09T06:06:07.577Z","updated_at":"2025-10-09T16:45:00.892Z","avatar_url":"https://github.com/akmjenkins.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# json-rules-engine-schema-operator\n\n[![npm version](https://img.shields.io/npm/v/json-rules-engine-schema-operator)](https://npmjs.org/package/json-rules-engine-schema-operator)\n[![codecov](https://codecov.io/gh/akmjenkins/json-rules-engine-schema-operator/branch/main/graph/badge.svg)](https://codecov.io/gh/akmjenkins/json-rules-engine-schema-operator)\n![Build Status](https://github.com/akmjenkins/json-rules-engine-schema-operator/actions/workflows/test.yaml/badge.svg)\n[![Bundle Phobia](https://badgen.net/bundlephobia/minzip/json-rules-engine-schema-operator)](https://bundlephobia.com/result?p=json-rules-engine-schema-operator)\n\n## What's This?\n\nIt's an operator to evaluate a value against a [JSON Schema](https://json-schema.org/) for the totally awesome [json-rules-engine](https://github.com/CacheControl/json-rules-engine) package.\n\n## Why?\n\nBecause a JSON Schema **is a predicate**. A value either validates against a schema, or it doesn't. Rather than writing (and maintaining) a bunch of custom operators and bloating your codebase with them, you only need one operator - a schema operator.\n\n## Installation\n\n```bash\nnpm install json-rules-engine-schema-operator\n# or\nyarn add json-rules-engine-schema-operator\n```\n\n## Usage\n\nThis package is BYOV - bring your own validator (highly recommend [AJV](https://github.com/ajv-validator/ajv)!!)\n\n```js\nimport Ajv from 'ajv';\nimport { Engine } from 'json-rules-engine';\nimport createSchemaOperator from 'json-rules-engine-schema-operator';\n\nconst ajv = new Ajv();\nconst validator = (subject,schema) =\u003e ajv.validate(schema,subject);\n\nconst engine = new Engine();\nengine.addOperator(createSchemaOperator(validator));\n```\n\nand now you can do this:\n\n```js\nengine.addRule({\n  conditions: {\n    any: [\n      {\n        fact: 'firstName',\n        operator: 'schema',\n        value: {\n          type: 'string',\n          pattern: '^J',\n        },\n      },\n    ],\n  },\n  event: {\n    type: 'j_firstName',\n  },\n});\n```\n\n## Custom Operator Name\n\nBy default, the name of the operator added to the engine is `schema`. This is configurable by passing in a custom name via the second optional parameter `options`:\n\n```js\nconst name = 'jsonSchemaOperator';\nengine.addOperator(validator, { name });\n\nengine.addRule({\n  conditions: {\n    any: [\n      {\n        fact: 'firstName',\n        operator: name,\n        value: {\n          type: 'string',\n          pattern: '^J',\n        },\n      },\n    ],\n  },\n  event: {\n    type: 'j_firstName',\n  },\n});\n```\n\n## Related\n\nI ❤️ JSON schema and [json-rules-engine](https://github.com/CacheControl/json-rules-engine) both so much, that I created a package [json-schema-rules-engine](https://github.com/akmjenkins/json-schema-rules-engine) that works very similarly, but it relies entirely on JSON schemas for predicates (or \"operators\"), which greatly simplifies the concept of the rules engine.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakmjenkins%2Fjson-rules-engine-schema-operator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakmjenkins%2Fjson-rules-engine-schema-operator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakmjenkins%2Fjson-rules-engine-schema-operator/lists"}