Modifier
Last updated
Last updated
The modifier is a very simple but powerful tool for on-the-fly data modification and transformation using code. It falls under the category of function extensions. Adding and deleting modifiers follows the same process as with the other extensions. Click the +
icon behind an output, modifier, filter, or error handler, and choose the Modifier
option.
Modifiers work akin to output, enabling you to leverage their value by linking to another function or a widget. The modifiers value is recalculated from the previous value after every trigger. The previous value can originate from an output, an error handler, a filter, or another modifier.
You can incorporate as many consecutive modifiers as needed.
To execute two or more independent modifications for the same output value, you can use the parallel modifier in one of two ways:
Click the +
icon behind a modifier
Select Parallel Modifier
Click the +
icon behind the function
Add a second Modifier
You can add as many parallel modifiers as required for your specific needs.
There are JSONata and JavaScript expression modifiers. By default, a modifier is set to JSONata.
The choice between JavaScript and JSONata often depends on your programming background. JavaScript may be more comfortable for those familiar with programming, while JSONata can be easier for beginners.
To switch between JSONata and JavaScript:
Right-click on an existing modifier
Select Jsonata
for JSONata or Expression
for JavaScript
When switching the modifier type, its content is deleted.
JSONata is a lightweight query and transformation language tailored for JSON data, and has been seamlessly integrated into Heisenware. JSONata offers support for sophisticated query expressions with minimal syntax, as well as its built-in operators and functions for efficiently manipulating and combining data.
The JSONata documentation and the exerciser are the best way to familiarize yourself with JSONata and its possibilities.
The two most essential and frequently used aspects of it are discussed below.
To refer to the value of a previous box, whether it's an output or a modifier itself, utilize the $
sign.
For JSONata functions, however, the previous value is automatically considered as an argument, eliminating the need to explicitly fill it into the brackets.
JSONata simplifies the task of filtering JSON objects significantly. You can achieve this by specifying a key in the modifier to filter it from an object.
A JavaScript expression is a unit of code that evaluates to a value. The modifier allows the use of evaluation expressions and integrates them seamlessly.
The variable x
contains the value of the preceding output or modifier and should not be used for any other purpose.
The expressions and operators documentation for JavaScript is a great starting point to get to know all the possibilities the modifier features has in store for you.
Pro tip: Immediately Invoked Function Expressions (IIFE) are supported as well.