# Transformation Function

### Overview

A **Transformation Function** in Qubitro allows you to **modify, rename, and structure incoming data** before it is stored or used for automation.

### How Transformation Functions Work

{% hint style="warning" %}
Transformation Functions run **after Decoder Functions** in a system-level order and cannot be changed.
{% endhint %}

{% @mermaid/diagram content="graph LR;
A\[Device Publishes Data] --> B{Decoder Function Exists?};

B -- Yes --> C\[Apply Decoder Function];
B -- No --> D\[Use Raw Data];

C --> E\[Apply Transformation Function];
D --> E;

E --> F\[Store Transformed Data in Qubitro];

%% Style Adjustments
style A fill:#d9d9d9,stroke:#000,color:#000;
style B fill:#f2f2f2,stroke:#000,color:#000;
style E fill:#e0e0e0,stroke:#000,color:#000;" %}

### JSONata for Data Transformation

Transformation Functions in Qubitro use [**JSONata**](https://jsonata.org/), a lightweight query and transformation language designed for JSON data.

{% hint style="info" %}
JSONata is optimized for real-time data processing, allowing flexible modifications without complex scripting.
{% endhint %}

<mark style="background-color:yellow;">For examples and best practices, check out our guidance.</mark>

{% embed url="<https://qubitro.gitbook.io/qubitro-documentation/guides/functions-and-data-processing/how-to-use-jsonata-for-real-time-data-transformation-in-qubitro>" %}

### Creating a Transformation Function

Transformation functions can be created from the **Functions tab** in the **device details page**:

{% stepper %}
{% step %}
**Open the Functions Tab**

1. Navigate to the **device details page** in the **Qubitro Portal**.
2. Click the **Functions** tab.
3. Click **Create function** and select **Transformation Function**.
4. Choose **JSONata** as the function type.
   {% endstep %}

{% step %}
**Write the JSONata Expression**

1. Enter your **JSONata transformation logic** in the editor.
2. Modify, restructure, or filter data as needed.
3. Click **Test** to validate the transformation output.

<figure><img src="/files/6KWgA1jdKmmn9nZh9RNw" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Save and Apply the Function**

1. Click **Save and complete** to activate the function.
2. The function will now **automatically process all incoming data** for this device.

{% hint style="success" %}
Transformation functions can be activated during creation or manually enabled/disabled under the **Configuration** page in the **Device Settings**.
{% endhint %}
{% endstep %}
{% endstepper %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.qubitro.com/platform/functions/transformation-function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
