You are here: Home » NewsFeeds » JsonLogic – Build complex rules, serialize them as JSON

JsonLogic – Build complex rules, serialize them as JSON

Table of Contents generated with DocToc

var

Retrieve data from the provided data object.

Most JsonLogic rules operate on data supplied at run-time. Typically this data is an object, in which case the argument to var is a property name.

jsonLogic.apply(
{ “var” : [“a”] }, // Rule
{ a : 1, b : 2 } // Data
);
// 1

If you like, we support syntactic sugar to skip the array around single values :

jsonLogic.apply(
{ “var” : “a” },
{ a : 1, b : 2 }
);
// 1

You can supply a default, as the second argument, for values that might be missing in the data object. (Note, the skip-the-array sugar won’t work here because you’re passing two arguments to var):

jsonLogic.apply(
{ “var” : [“z”, 26] }, // Rule
{ a : 1, b : 2 } // Data
);
// 26

The key passed to var can use dot-notation to get the property of a property (to any


 

Original article