enhanced-json-logic-js
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-rc1 • Public • Published

json-logic-js

This parser accepts JsonLogic rules and executes them in JavaScript.

The JsonLogic format is designed to allow you to share rules (logic) between front-end and back-end code (regardless of language difference), even to store logic along with a record in a database. JsonLogic is documented extensively at JsonLogic.com, including examples of every supported operation and a place to try out rules in your browser.

The same format can also be executed in PHP by the library json-logic-php

Examples

Simple

jsonLogic.apply( { "==" : [1, 1] } );
// true

This is a simple test, equivalent to 1 == 1. A few things about the format:

  1. The operator is always in the "key" position. There is only one key per JsonLogic rule.
  2. The values are typically an array.
  3. Each value can be a string, number, boolean, array (non-associative), or null

Compound

Here we're beginning to nest rules.

jsonLogic.apply(
  {"and" : [
    { ">" : [3,1] },
    { "<" : [1,3] }
  ] }
);
// true

/enhanced-json-logic-js/

    Package Sidebar

    Install

    npm i enhanced-json-logic-js

    Weekly Downloads

    1

    Version

    1.0.0-rc1

    License

    MIT

    Unpacked Size

    41.9 kB

    Total Files

    10

    Last publish

    Collaborators

    • ngonzalezromero