
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
json-rules-engine-to-json-logic
Advanced tools
A minimal Typescript library for converting a json-rules-engine condition to a JsonLogic rule specification.
:warning: This package is under active development: Compatibility and APIs may change.
Why? • Key Features • Installation • API • Example • Compatibility • See Also • License
From the json-rules-engine README:
json-rules-engineis a powerful, lightweight rules engine. Rules are composed of simple json structures, making them human readable and easy to persist.
Rule engines often come in handy because they allow you to:
eval)Because of this, user defined rules can be persisted and securely evaluated on both your frontend and backend, making them ideal for scenarios when you need to allow configurable rules to be securely evaluated during runtime (e.g. an automation engine).
There are many 3rd party libraries that depend on rules engines, json-logic being one of the more popular options. As such, these libraries often expect as input, or they output a json-logic rule. This can sometimes be an issue as it might force you to adopt json-logic throughout your entire application, or it might mean you're unable to use those libraries if you choose to roll a different engine.
By providing the means to convert a json-rules-engine condition to a json-logic rule, json-rules-engine-to-json-logic allows you to take advantage of libraries that integrate with json-logic without having to adopt it across your entire application should you want to use json-rules-engine.
1kb minified + zipped$ npm install json-rules-engine-to-json-logic
toJsonRule(condition: JsonRulesEngineCondition): JsonLogicRuleConverts a json-rules-engine condition to a json-logic rule.
import { toJsonRule } from "json-rules-engine-to-json-logic";
const jsonLogicRule = toJsonRule({
all: [
{
fact: "name",
operator: "equal",
value: "Harry Potter",
},
],
});
// => { and: [{ "===": [{ var: "name" }, "Harry Potter"] }] };
CompatibilityError(message: string)Thrown on failed conversions when the json-rules-engine condition uses functionality that can't be converted. Contains the following properties:
name: "CompatibilityError"message: a string, indicating what was incompatible.import { toJsonRule } from "json-rules-engine-to-json-logic";
import { Engine } from "json-rules-engine";
import jsonLogic from "json-logic-js";
const facts = {
name: "Harry Potter",
};
const conditions = {
all: [
{
fact: "name",
operator: "equal",
value: "Harry Potter",
},
],
};
// evaluate using json-rules-engine
const engine = new Engine();
engine.addRule({
conditions,
event: { type: "isHarry" },
});
const result = await engine.run(facts);
const jsonRulesResult = result.results.length > 0;
// evaluate using json-logic
const jsonLogicRule = toJsonRule(conditions);
const jsonLogicResult = jsonLogic.apply(jsonLogicRule, facts);
// assert both return the same result
console.assert(jsonLogicResult === jsonRulesResult);
This is available in the examples
Given both libraries offer different functionality, it is impossible to 100% convert between one and the other. In the case where a conversion isn't possible, a Compatibility error will be thrown, or a feature will be ignored. Current incompatibilities include:
json-rules-engine uses json-path whereas json-logic uses dot notation. json-path is the more powerful of the two, and a lot of functionality doesn't port over. A Compatibility error will be thrown if a condition uses json-path functionality that can't be ported over to dot notation.json-rules-engine provides a params property that allows you to create function handlers to provide dynamic facts during run-time. This isn't possible with json-logic and is therefore ignored.FAQs
A minimal Typescript library for converting a json-rules-engine condition to a JsonLogic rule specification.
The npm package json-rules-engine-to-json-logic receives a total of 8 weekly downloads. As such, json-rules-engine-to-json-logic popularity was classified as not popular.
We found that json-rules-engine-to-json-logic 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
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.