Table of contents
- Introduction
- Code Transformer Functionality
- Limitations
- Examples
Introduction
The Code transformer allows users to write JavaScript code to manipulate and transform data.
To get to the page, navigate the following path: Transformers → Create a new transformer.
Code Transformer Functionality
To create a new Code transformer, use the following steps:
Step 1: Create a transformer and select Data, transform data using mappers and conditions.
Step 2: Add Data transformer → Code transformer.
Step 3: Input proper information into the required fields such as:
- Source Field: Users can input a JMESPath query to select the specific data that needs transformation. This selected data is then accessible within the Code transformer through the variable
data
. - Code Field: This field contains the JavaScript code. All data returned will become available in the path defined in the Destination field.
- Destination Field: This field specifies the path where the transformed output will be stored.
Limitations
The Code transformer is subject to a memory limit of 16MB and a maximum execution time of 2 seconds. These constraints are in place to prevent issues such as infinite loops. Additionally, JavaScript functions like fetch
are not supported. If HTTP requests are necessary, the regular HTTP transformer should be added before the Code transformer.
Examples
In the following example, an array of products is transformed using the Code Transformer. For each product, a new price is calculated and added to the data. The transformed data is then returned and made available in the products
property of the current data.
Transformer example
Input data example
Result example