Using logical statements (JsonLogic)

In manifest JsonLogic is used for visibility and disabled conditions, for figuring out next screen user needs to be taken and in request data transformers.

interface JsonLogic {
  type: "jsonlogic";
  schema: JsonLogic;
}

JsonLogic can access variables (more info). Currently these state slices are exposed: input, flags, quote, dataset, context, document, route and query_string.

Custom operators

iso_date

It takes in Date object and returns ISO String of it. If value passed in is not Date object, there will be a warning message and output will be untouched value that was passed in.

This is useful when input has Date object, but some operations have to be made with this value using JsonLogic (e.g. substr to get year, month, day etc.).

LogicDateResult

{ "iso_date": {"var":"date"} }

{ date: new Date() }

"2019-06-11"

This operator can also accept modifier value as a second (optional) parameter, that is a string.

LogicDateResult

{ "iso_date": [{"var":"date"}, "-5 days"}

{ date: new Date() }

"2019-06-06"

{ "iso_date": [{"var":"date"}, "+1 month"}

{ date: new Date() }

"2019-07-11"

{ "iso_date": [{ "iso_date": [{"var":"date"}, "+2 years"}, "-1 day"}

{ date: new Date() }

"2021-06-10"

length

Returns length of array.

LogicInputResult

{ "length": { "var": "input.numbers" }}

{ numbers: ['a', 'b', 'c'] }

3

to_object

Builds object from flat entries list.

LogicInputResult

{"to_object": ["foo", 1, "bar", 2]}

...

{"foo": 1, "bar": 2}

path

This is deprecated functionality, please don't use this!

Instead use "cat" operator:

{"var": {"cat": ["input.agents.", {"var": "context.repeater_index"}, ".name"]}}

Has ability to access context from string.

Let's say you have repeater component and in there you must have ability to show/hide field with jsonlogic based on value on particular field in repeater array. We can use path operator in combination with var to do so.

With data:

{
  "agents": [
    {
      "name": "John"
    },
    {
      "name": "Jane"
    },
    {
      "name": "Alfred"
    }
  ]
}
LogicContextResult

{"path": "agents.{repeater_index}.name"}

{ repeater_index: 2 }

"agents.2.name"

{"var": {"path": "agents.{repeater_index}.name"}}

{ repeater_index: 2 }

"Alfred"

Last updated