Modifier

Modifiers transform data on the fly within a flow. They allow you to apply a JSONata or JavaScript expression to change the structure or value of an output before passing it to the next function, a database, the frontend, or a subsequent extension (such as another modifier or filter).

Modifiers are part of the function extensions. To add a modifier to your function:

  1. Click the + icon on the right side of any function output, filter, or existing modifier.

  2. Select modifier from the list.

  3. A new modifier box will appear where you can write your JavaScript logic.

A modifier uses either JSONata or a JavaScript expression. You can switch between types by right-clicking the modifier and selecting JSONata or Expression and adjust the default inside the App Builder settings.

circle-check

JSONata

JSONata is a query and transformation language designed for JSON data. It is the preferred method for structural changes, filtering, and simple math. For a complete guide, refer to the official JSONata documentationarrow-up-right.

  • Reference: Use the $ sign to refer to the value from the preceding output.

  • Implicit arguments: In Heisenware, JSONata modifiers automatically process the incoming data if the parentheses are left empty. For example, $uppercase() is equivalent to $uppercase($).

JSONata examples

chevron-rightExample 1: Path selection and mathhashtag

Extracts a specific nested value from a PLC object and performs a calculation.

Data:

Modifier content:

Return of the modifier:

chevron-rightExample 2: Wrap a value in an object hashtag

Takes the incoming value ($) and wraps it inside a JSON object with a key named temp_sensor_1.

Data:

Modifier content:

Return of the modifier:

chevron-rightExample 3: Implicit function usage hashtag

Trims whitespace and converts a raw string to uppercase without explicitly naming the input variable.

Data:

Modifier content:

Return of the modifier:

chevron-rightExample 4: Filtering an array hashtag

Returns only the objects from a list that meet a specific status condition.

Data:

Modifier content:

Return of the modifier:

JavaScript expressions

This modifier allows you to use any standard JavaScript expression that evaluates to a new value. Reference the reserved variable x to access the preceding data output. For more information, refer to the MDN documentation for JavaScript Expressions and Operatorsarrow-up-right.

JavaScript expression examples

chevron-rightExample 1: Conditional status (Ternary) hashtag

Determines a status string based on a numeric threshold.

Data:

Modifier content:

Return of the modifier:

chevron-rightExample 2: Array mapping and enrichmenthashtag

Iterates through an array of objects to add a new property or modify existing ones using the .map() function.

Data:

Modifier content:

Return of the modifier:

chevron-rightExample 3: Multi-step logic (IIFE)hashtag

While modifiers only support expressions, you can use the Immediately Invoked Function Expression (IIFE) pattern for more elaborate logic involving temporary variables.

Data:

Modifier content:

Return of the modifier:

chevron-rightExample 4: Removing and adding properties in an arrayhashtag

Use the spread operator (...) to reproduce existing entries while selectively removing or adding properties.

Data:

Modifier content:

Return of the modifier:

chevron-rightExample 5: Processing multiple inputs (using combine function)hashtag

When using the combine function, the IIFE pattern allows you to cleanly handle multiple input sources stored in the x array.

Data (combined by the combine function):

Modifier content:

Return of the modifier:

chevron-rightExample 6: Date calculations (using Luxon)hashtag

Heisenware provides built-in support for the Luxonarrow-up-right library via the DateTime object for complex time-series operations.

Data:

Modifier content:

Return of the modifier:

chevron-rightExample 7: Round robin (using combine function)hashtag

Sometime you want to extract items of an array in a round-robin fashion. For that you can use a combine function in which you link back the modifier's output to the second argument:

Data:

Modifier content:

Return of the modifier:

Using AI for modifiers

You can use AI chatbots (ChatGPT, Claude, Gemini) to generate or optimize your modifiers. This is particularly helpful for complex data transformations where you need to reshape large JSON objects on the fly within the Heisenware visual programming environment.

To optimize results, copy this article as context for the AI. Use the Copy button at the top of the page or the direct Open in ChatGPT / Open in Claude buttons located in the top navigation bar.

Alternatively to using the full article, copy and paste this prompt into your AI to ensure it understands the Heisenware environment and specific variable references.

Last updated

Was this helpful?