How to Use JSONata for Real-Time Data Transformation in Qubitro
Last updated
Last updated
This guide explains how to use JSONata expressions in Qubitro Transformation Functions to manipulate and structure real-time data before it is stored or used for automated actions.
JSONata provides a flexible, lightweight way to filter, calculate, and restructure data without writing traditional code.
A few things to remember:
Data can be modified on-the-fly before storage and automation.
TF applies immediately to incoming data, whether raw or already decoded.
Once a device sends data, TF automatically applies the JSONata expression configured by the user.
If a Decoder Function exists, it will process raw data first, and then TF will apply JSONata expressions on the decoded output. If there is no decoder, TF will apply transformations directly to the published data.
Here are some core JSONata concepts:
Mathematical functions: $sum(values), $average(values), $max(values), $min(values).
Ternary operators: condition ? trueValue : falseValue.
String and numeric literals: "text" for strings, 42 for numbers.
Using the root object: $ refers to the root JSON object.
Accessing fields: fieldname retrieves a specific property.
Convert a multi-level JSON object into a flat structure for better Qubitro compatibility.
Transform an array of objects into structured key-value pairs.
Use JSONata to compute sums, averages, and find min/max values dynamically.
Modify timestamps into human-readable formats or compute durations.
This method is useful when field names may change dynamically.