Neurological Phenomenon Multiplexer
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

json-logic

2.0.0 • Public • Published

node-json-logic

Package for expressing logical operations in JSON. Useful for storing logical procedures in a database.

Examples of use

var JSONMath = require('json-logic');
var logic = new JSONLogic();
var result = logic .execute({
    "a": {
        "operation": "||",
        "variables": [
            {
                "operation": "<",
                "variables": [
                    5,
                    1
                ]
            },
            {
                "operation": "&&",
                "variables": [
                    {
                        "operation": "==",
                        "variables": [
                            8,
                            2
                        ]
                    },
                    true
                ]
            }
        ]
    }
});

After this has executed, the value of a will be false.

You can also pass in an array of operations to perform, and even reference variables inside the procedure

[
    {
        "a": true,
        "b": false
    },
    {
        "c": {
            "operation": "&&",
            "variables": [
                "a",
                "b"
            ]
        }
    },
    {
        "c": "c"
    }
]

After this the value of a will be true, b will be false and c will be false.

Keywords

Install

npm i json-logic

DownloadsWeekly Downloads

52

Version

2.0.0

License

MIT

Last publish

Collaborators

  • avatar