
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
json-rules-engine-schema-operator
Advanced tools
An operator for json-rules-engine to evaluate a value against a JSON schema
It's an operator to evaluate a value against a JSON Schema for the totally awesome json-rules-engine package.
Because 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.
npm install json-rules-engine-schema-operator
# or
yarn add json-rules-engine-schema-operator
This package is BYOV - bring your own validator (highly recommend AJV!!)
import Ajv from 'ajv';
import { Engine } from 'json-rules-engine';
import createSchemaOperator from 'json-rules-engine-schema-operator';
const ajv = new Ajv();
const validator = (subject,schema) => ajv.validate(schema,subject);
const engine = new Engine();
engine.addOperator(createSchemaOperator(validator));
and now you can do this:
engine.addRule({
conditions: {
any: [
{
fact: 'firstName',
operator: 'schema',
value: {
type: 'string',
pattern: '^J',
},
},
],
},
event: {
type: 'j_firstName',
},
});
By 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
:
const name = 'jsonSchemaOperator';
engine.addOperator(validator, { name });
engine.addRule({
conditions: {
any: [
{
fact: 'firstName',
operator: name,
value: {
type: 'string',
pattern: '^J',
},
},
],
},
event: {
type: 'j_firstName',
},
});
I ❤️ JSON schema and json-rules-engine both so much, that I created a package 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.
FAQs
An operator for json-rules-engine to evaluate a value against a JSON schema
The npm package json-rules-engine-schema-operator receives a total of 0 weekly downloads. As such, json-rules-engine-schema-operator popularity was classified as not popular.
We found that json-rules-engine-schema-operator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.