Modifier
Modifiers transform data on the fly within a flow. Apply a JSONata or JavaScript expression to change the structure or value of an output before it reaches the next function, a database, the frontend, or a subsequent extension node (such as another modifier or a filter).
To add a modifier:
Click the + icon on the right side of a function output, filter, or existing modifier.
Select Modifier from the list.
Click the new modifier node (Click to edit...) to open the code editor and write your expression.
A modifier uses either JSONata or a JavaScript expression. Switch between types by right-clicking the modifier and selecting JSONata or Expression. Adjust the default type in the App Builder settings.
Click the modifier icon on the left to evaluate the modifier manually during development. The last result appears below the expression. Right-click also lets you add a comment to the modifier or delete it.

Need help writing modifiers?
Read how to use AI for modifiers to generate JSONata or JavaScript logic with your favorite chatbot.
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, see the official JSONata documentation.
Reference: Use the
$sign to refer to the value from the preceding output.Implicit arguments: JSONata modifiers automatically process the incoming data if the parentheses are left empty. For example,
$uppercase()is equivalent to$uppercase($).
JSONata examples
Example 1: Path selection and math
Extracts a specific nested value from a PLC object and performs a calculation.
Data:
Modifier content:
Return of the modifier:

Example 2: Wrap a value in an object
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:

Example 3: Implicit function usage
Trims whitespace and converts a raw string to uppercase without explicitly naming the input variable.
Data:
Modifier content:
Return of the modifier:

Example 4: Filtering an array
Returns only the objects from a list that meet a specific status condition.
Data:
Modifier content:
Return of the modifier:

JavaScript expressions
This modifier type accepts any standard JavaScript expression that evaluates to a new value. Reference the reserved variable x to access the preceding data output. For more information, see the MDN documentation on JavaScript expressions and operators.
JavaScript expression examples
Example 1: Conditional status (ternary)
Determines a status string based on a numeric threshold.
Data:
Modifier content:
Return of the modifier:

Example 2: Array mapping and enrichment
Iterates through an array of objects to add a new property or modify existing ones using .map().
Data:
Modifier content:
Return of the modifier:

Example 3: Multi-step logic (IIFE)
Modifiers only support expressions. For more elaborate logic involving temporary variables, use the Immediately Invoked Function Expression (IIFE) pattern.
Data:
Modifier content:
Return of the modifier:

Example 4: Removing and adding properties in an array
Use the spread operator (...) to reproduce existing entries while selectively removing or adding properties.
Data:
Modifier content:
Return of the modifier:

Example 5: Processing multiple inputs (using combine)
When using the combine function, the IIFE pattern cleanly handles multiple input sources stored in the x array.
Data (combined by the combine function):
Modifier content:
Return of the modifier:

Example 6: Date calculations (using Luxon)
Heisenware provides built-in support for the Luxon library via the DateTime, Duration, and Interval objects for complex date and time operations.
Duration and Interval are only available from version v91.
Here are some common modifier patterns:
1. Calculating future or past dates (addition and subtraction)
Data:
Modifier content:
Return of the modifier:

2. Calculating downtime (time differences)
Find the exact duration between two timestamps, such as a machine fault start and end time.
Data:
Modifier content:
Return of the modifier:
3. Formatting decimal labor hours
Convert raw decimal hours from timesheets or logs into standard HH:mm timecode using the Duration object.
Data:
Modifier content:
Return of the modifier:
4. Validating events against shifts (intervals)
Check if a specific event (like a sensor trigger) occurred within a defined time window or shift using the Interval object.
Data:
Modifier content:
Return of the modifier:
5. Converting UTC sensor data to local time
IoT devices typically send data in UTC. Convert this to a readable local format for UI dashboards.
Data:
Modifier content:
Return of the modifier:
Example 7: Round robin (using combine)
Sometimes you want to extract items of an array in a round-robin fashion. Use a combine function in which you link the modifier's output back to the second argument:

Data:
Modifier content:
Return of the modifier:
Using AI for modifiers
Use AI chatbots (ChatGPT, Claude, Gemini) to generate or optimize your modifiers. This helps especially with complex transformations where you need to reshape large JSON objects on the fly.
For best results, copy this article as context for the AI. Use the Copy button at the top of the page or the Open in ChatGPT / Open in Claude buttons in the top navigation bar.
Recommended AI prompt
Alternatively, copy and paste this prompt into your AI so it understands the Heisenware environment and its variable references.
Last updated
Was this helpful?