Functions
JSONata

April 18, 2024

How to Apply JSONata Expressions for Real-Time Data Processing in Qubitro

Using JSONata in the Qubitro platform for data transformation allows for on-the-fly manipulation of data, turning complex JSON structures into straightforward key-value pairs.

The JSONata expressions you've been working with can be conveniently applied within Qubitro using Transformation Functions. These functions allow you to manipulate and process real-time data streams using JSONata syntax.

Understanding JSONata

JSONata is akin to SQL for databases, but designed specifically for JSON. It allows users to perform advanced data search, filter, and transformation with simplicity.

Basic Syntax and Operators

Familiarize yourself with some of the key JSONata syntax and operators:

  • Field Access: Use fieldname to access a specific property.
  • String Literals: Specify "string" to represent text.
  • Numeric Literals: Use 42 to represent numbers.
  • Root Object: The $ symbol denotes the root of the data.
  • Ternary Operator: Apply condition ? trueResult : falseResult to determine outputs based on a condition.

NOTE: JSONata can be utilized for a wide range of data manipulation tasks from the simplest to the most complex.

Example 1: Flattening Nested JSON

Convert nested JSON objects into a flat key-value structure.

Incoming JSON Data

JSONata Transformation

Transformed JSON Data

Example 2: Simplifying Array Data

Turn an array of objects into a series of individual key-value pairs.

Incoming JSON Data

JSONata Transformation

Transformed JSON Data

Example 3: Complex Data Transformation

Convert complex, multi-level IoT data into a single-level object with clear key-value pairs.

Incoming JSON Data

JSONata Transformation

Transformed JSON Data

Example 4: Mathematical Operations

Perform basic arithmetic on sensor data, such as calculating the sum, average, or other mathematical transformations.

Incoming JSON Data

JSONata Transformation for Sum and Average

Transformed JSON Data

Example 5: Time Formatting

Transform and format timestamps from sensors to more human-readable formats or calculate durations between timestamps.

Incoming JSON Data

JSONata Transformation for Human-Readable Date and Duration

Transformed JSON Data

Example 6: Accessing Data Dynamically Using $ Syntax

Dynamically access properties in a JSON object without directly referencing the keys, useful for schemas where the exact keys might not be known in advance or may vary.

Incoming JSON Data

JSONata Transformation Using $ to Dynamically Access Values

Transformed JSON Data

Example 7: Performing Calculations Dynamically

Use $ syntax to apply a generic calculation across multiple fields dynamically, which is helpful when dealing with varying data structures.

Incoming JSON Data

JSONata Transformation to Sum Values Dynamically

Transformed JSON Data

Example 8: Dynamic Date Formatting

Format any date value in a JSON object dynamically, without knowing the key under which the date is stored.

Incoming JSON Data

JSONata Transformation for Dynamic Date Formatting

Transformed JSON Data

Conclusion

These examples illustrate the power of JSONata in transforming complex IoT data into easily manageable forms. Qubitro's integration of JSONata facilitates efficient data handling and decision-making processes in IoT systems.

For more comprehensive guides and concepts, visit the official JSONata Documentation.

Couldn't find the guide you need?
    Qubitro Logo

    Product

    Resources

    Industries

    Decision Aids

    Solutions

    Company

    © 2024 Qubitro, Inc. All rights reserved