Registry / devops / json-logic-js-graphql

json-logic-js-graphql

JSON →
library1.2.4jsnpmunverified

json-logic-js-graphql extends json-logic-js with GraphQL-compatible Lodash methods, enabling the use of logical operators like `_eq`, `_gt`, `_gte`, `_lt`, `_lte`, `_and`, `_or`, and date functions via moment.js. Current stable version is 1.2.4, released in 2021 with low release cadence. It solves the problem that GraphQL does not support keys like `==` or `===` by providing underscore-prefixed alternatives. Differs from plain json-logic-js by adding Lodash utility functions exposed as operators, and includes moment.js date comparisons. Suitable for applications that need to store or pass JSON Logic rules in GraphQL mutations.

npm install json-logic-js-graphql
INSTALL
IMPORT
SIG · JSON-LOGIC-JS-GRAP
J
json-logic-js-graphql
devopsjavascriptv1.2.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

jsonLogic
import { jsonLogic } from 'json-logic-js-graphql'
import jsonLogic from 'json-logic-js-graphql'
Named export only; no default export exists.
addOperators
import { addOperators } from 'json-logic-js-graphql'
const addOperators = require('json-logic-js-graphql').addOperators
addOperators is a named export; requires adding JsonLogic rules manually. Usage: addOperators(jsonLogic).

Shows usage of json-logic-js-graphql with _and, _eq, _gt operators, and logging the result.

import { jsonLogic } from 'json-logic-js-graphql'; import moment from 'moment'; // Define rules using underscore-prefixed operators const rules = { _and: [ { _eq: [{ var: 'foo' }, 'bar'] }, { _gt: [{ var: 'count' }, 10] } ] }; const data = { foo: 'bar', count: 15 }; const result = jsonLogic.apply(rules, data); console.log(result); // true
Debug
Known issues
breakingDefault jsonLogic operators (==, ===, etc.) are not available when using GraphQL; you must use underscore-prefixed alternatives.
fix
Replace operators like `==` with `_eq`, `>` with `_gt`, etc.
affects: >=1.0.0
deprecatedmoment.js is used for date functions but is considered a legacy library; may affect long-term maintainability.
fix
Consider using an alternative date library or implementing custom date operators.
affects: >=1.0.0
gotchaThe package does not export a default; a named import is required.
fix
Use `import { jsonLogic } from 'json-logic-js-graphql'` instead of default import.
affects: >=1.0.0
gotchaLodash methods are exposed with `_` prefix but not all Lodash functions are supported; only those listed in operators.js.
fix
Check the operators.js file in the package or the GitHub repository for the complete list.
affects: >=1.0.0
gotchaDate functions like _gteDate expect moment-duration format as second argument; misformatting leads to errors.
fix
Ensure the second argument is an array like [number, 'unit'], e.g., [364, 'days'].
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'json-logic-js'
json-logic-js not installed or not resolved as a dependency.
fix
Run `npm install json-logic-js` or `yarn add json-logic-js`.
jsonLogic.apply is not a function
Wrong import (default import instead of named) or jsonLogic not initialized.
fix
Use `import { jsonLogic } from 'json-logic-js-graphql'` and ensure jsonLogic is defined.
Upgrade
Version history
1.2.4latest on npm
Audit
Dependencies
json-logic-jsrequiredCore library for JSON Logic evaluation; required as a peer dependency or bundled.
lodashrequiredProvides the utility functions exposed as operators (_eq, _gt, etc.).
momentoptionalUsed for date functions like _gteDate, _gtDate, etc.
Agent activity
13 hits · last 30 days
node
10
Amazon
1
Resources
json-logic-js-graphql — npm install json-logic-js-graphql · libregistry