JavaScript Eval
![]()
Description
The JavaScript Eval processor allows you to write custom JavaScript functions to transform and enrich events. It:
- Executes user-defined JavaScript code
- Provides full access to input event data
- Supports complex data transformations
- Enables dynamic field creation and modification
Required Input
The processor works with any input event stream. All fields from the input event are available as properties in the JavaScript function.
Configuration
JavaScript Function
You need to provide a JavaScript function that processes the input event and returns a new event object. The function must:
- Be named
process - Accept a single parameter containing the input event
- Return a map/object with the output fields
Example function structure:
function process(event) {
// do processing here.
// return a map with fields that matched defined output schema.
return {id: event.id, tempInCelsius: (event.tempInKelvin - 273.15)};
}
The defined output schema must match the event that is returned by the JavaScript function.
Output
The processor forwards a new event containing the fields returned by your JavaScript function.
Example
Input Event
{
"temperature": 25.5,
"humidity": 60,
"timestamp": 1586380105115
}
Configuration
function process(event) {
// Convert temperature from Celsius to Fahrenheit
const tempF = (event.temperature * 9/5) + 32;
// Calculate heat index
const heatIndex = calculateHeatIndex(tempF, event.humidity);
// Return new event with transformed data
return {
temperature_celsius: event.temperature,
temperature_fahrenheit: tempF,
humidity: event.humidity,
heat_index: heatIndex,
timestamp: event.timestamp
};
}
function calculateHeatIndex(temp, humidity) {
// Simplified heat index calculation
return temp + (humidity * 0.1);
}
Output Event
{
"temperature_celsius": 25.5,
"temperature_fahrenheit": 77.9,
"humidity": 60,
"heat_index": 83.9,
"timestamp": 1586380105115
}
Use Cases
-
Data Transformation
- Unit conversions
- Data normalization
- Complex calculations
- Field restructuring
-
Data Enrichment
- Adding derived fields
- Computing statistics
- Combining multiple fields
- Creating calculated metrics
-
Custom Logic
- Business rules implementation
- Conditional transformations
- Data validation
- Custom algorithms
Notes
- The JavaScript function runs in a GraalVM JavaScript environment
- All input fields are accessible as properties of the event object
- The function must return a valid JavaScript object
- Error handling should be implemented in the JavaScript code
- Complex JavaScript operations are supported
- The function is executed for each incoming event, but state can be kept