json-logic-js

A lightweight JavaScript engine for building, storing, and executing JsonLogic rules across the front-end, back-end, and database.

Library
npm
v2.0.5
1,488 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
44 /100 Fair
Development Activity 0
Maintenance 20
Community 56
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
63 /100 Good
Architecture 58
Code Quality 62
Innovation 75
Learning Curve 55

json-logic-js is the JavaScript implementation of JsonLogic, a shared rule format that expresses conditional logic as plain JSON so the same rule set can run identically across languages, environments, and databases. A rule is a single-key object mapping an operator to its arguments, which makes rules simple enough to author by hand, generate from a UI, store next to a database record, or send over an API — without duplicating business logic in every language that needs to evaluate it.

The library ships as a single dependency-free UMD module (logic.js) that runs unmodified in the browser, in Node via CommonJS, or through an AMD loader. It implements the full core JsonLogic operator set — comparisons, boolean logic, arithmetic, string operations, and array operations like map, filter, reduce, all, some, and none — plus data access via var, validation helpers (missing, missing_some), and utilities for introspecting rules (uses_data, rule_like) or registering custom operators at runtime.

What You Get

  • A single self-contained logic.js UMD module with zero runtime dependencies, usable via npm, a <script> tag, or an AMD loader
  • A complete JsonLogic operator set out of the box: comparisons, boolean logic, arithmetic, string operations, and array operations (map, filter, reduce, all, some, none)
  • var, missing, and missing_some operators for reading and validating fields on a data object supplied at evaluation time
  • add_operation/rm_operation for registering or removing custom operators at runtime, plus rule_like/uses_data for pattern-matching and introspecting rules before running them

Common Use Cases

  • Storing user-configurable business rules (pricing, eligibility, feature flags) as JSON in a database and evaluating them at request time
  • Sharing a single validation or eligibility rule set between a Node backend and a browser front-end without reimplementing the logic twice
  • Building a visual rule builder UI where non-developers compose conditions that compile directly to JsonLogic
  • Running the same rule against different data shapes to unit-test business logic without redeploying code

Under The Hood

Architecture

The entire library lives in one UMD-wrapped module built around a single recursive dispatcher, jsonLogic.apply(logic, data). Most operators are simple functions in a flat operations lookup table that receive their evaluated arguments and the data object as this; a handful of operators that need to control their own recursion or short-circuit (if, and, or, filter, map, reduce, all, none, some) are special-cased directly inside apply before falling through to the generic depth-first evaluation path. This keeps the control flow centralized in one function rather than split across files, so extending the language for anything beyond a plain value-in/value-out operator means editing that dispatcher directly rather than composing independent pieces — a workable design at this size, but one where every feature ultimately funnels through a single, growing conditional chain.

Tech Stack

Plain, dependency-free JavaScript targeting broad compatibility: the module uses the UMD pattern to support CommonJS (module.exports), AMD (define), and a global window.jsonLogic fallback from one file, with package.json pointing main directly at the unbundled logic.js — there is no build or bundling step in the publish path. Development tooling is limited to ESLint (Google config) for linting and QUnit for the test runner; there are no runtime dependencies and no TypeScript, so consumers get JavaScript with community-maintained type definitions rather than first-party types.

Code Quality

Testing is thorough for the library’s scope: the QUnit suite in tests/tests.js downloads a shared, cross-language conformance test set (tests.json, rule_like.json) from jsonlogic.com — the same fixtures used to validate JsonLogic ports in other languages — and layers on hand-written edge-case tests for falsy data, custom operator registration, and error paths. Error handling is explicit: unrecognized operators throw a descriptive Error rather than failing silently. No CI workflow configuration is present in the repository, and there is no static type system, so correctness relies on the conformance suite plus ESLint rather than compiler-enforced guarantees.

API Design The public surface is intentionally tiny: one entry point, jsonLogic.apply(rule, data), evaluates any rule against any data object, with syntactic sugar that lets unary operators skip the surrounding array ({"var": "a"} instead of {"var": ["a"]}). Getting started requires no setup beyond importing the module and calling apply — there’s no configuration object, no class to instantiate, and no boilerplate. add_operation extends the language with the same low ceremony, and the operator vocabulary mirrors the shared JsonLogic spec documented (with a live playground) at jsonlogic.com, which lowers the learning curve for anyone who has seen JsonLogic in another language.

Used by 6 apps in this directory

Ruby
51%
Other

Chatwoot

Customer Support

38,155

Open-source omnichannel customer support platform with AI-powered agents, live chat, and self-hosting — a full Intercom and Zendesk alternative.

View details
95
Repo Health
78
Technical
66
Dependency
Built with
Ruby 51%
Vue 25%
JavaScript 22%
Updated 5 days ago
TypeScript
98%
Other

Novu

Developer Tools

40,195

Open-source communication infrastructure that connects your products and AI agents to every channel your users live on — Inbox, Email, SMS, Push, Chat, and more.

View details
93
Repo Health
80
Technical
64
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
90%
MIT

Plasmic

CMS · Design Tools · Low Code Platforms

7,125

The open-source visual builder that lets teams design React apps and websites with drag-and-drop while integrating seamlessly with your codebase.

View details
81
Repo Health
78
Technical
64
Dependency
Built with
TypeScript 90%
Updated 6 days ago
TypeScript
89%
Other

strapi

CMS

73,368

Open-source headless CMS that auto-generates REST and GraphQL APIs from your content models, with a fully customizable admin panel you control.

View details
93
Repo Health
84
Technical
63
Dependency
Built with
TypeScript 89%
JavaScript 11%
Updated 6 days ago
TypeScript
72%
Apache 2.0

Supabase

Authentication · Databases · Developer Tools

113,827

The open-source Postgres development platform that replaces Firebase with authentication, real-time APIs, edge functions, storage, and vector embeddings — all built on PostgreSQL.

View details
90
Repo Health
91
Technical
62
Dependency
Built with
TypeScript 72%
MDX 26%
Updated 5 days ago
TypeScript
84%
Other

twenty

CRM

59,615

The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.

View details
92
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 84%
MDX 14%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers