Concepts
Transforms
Transforms allow you to manipulate data on the fly, which can be the event or attribute's payload, or the actual body that is transported to different destinations.
Anatomy of a transform#
An individual transform is based on the following properties:
type
(required): the type of the transform (see below)- A source to transform (see sources page), with properties like:
source
attribute
payload
lookup
target
: the target property to set/update the value invalue
: the value to set/update the target property with
Types of transforms#
set#
If starting the transformation process with an empty object:
transforms: - type: set value: {}
If setting in a specific target property:
transforms: - type: set target: myProperty # can be dot-separated path value: myValueHere
If getting value from a source and then setting it to a target property:
transforms: - type: set source: eventName target: event
remove#
Some properties may not be needed, and you can remove them:
transforms: - type: remove target: myProperty # can be dot-separated path
rename#
You can rename multiple properties at once:
transforms: - type: rename targetMap: existingProperty: newProperty # paths can be dot-separated
If the renames need to be done in a sequential manner, you can make use of arrays in targetMap
:
transforms: - type: rename targetMap: - existingProperty: newProperty - existingProperty2: newProperty2
NOTE: This API may change in the future.
trim#
To trim whitespace from the beginning and end of a string value:
transforms: - type: trim target: myProperty # can be dot-separated path
toInteger#
Convert a value to an integer:
transforms: - type: toInteger target: myProperty # can be dot-separated path
toDouble#
Convert a value to a double (float):
transforms: - type: toDouble target: myProperty # can be dot-separated path
toBoolean#
Convert a value to a boolean:
transforms: - type: toBoolean target: myProperty # can be dot-separated path
toString#
Convert a value to a string:
transforms: - type: toString target: myProperty # can be dot-separated path
spread#
This is very useful if you would like to spread, let's say, the current attributes into the payload itself:
transforms: - type: spread source: attributes
This is JavaScript's equivalent of doing:
// sourcesconst attributes = { deviceId: "device-123", userId: "user-456" };const payload = { someProperty: "some value" };// transformsconst result = { ...payload, ...attributes };
increment#
To increment a value by 1:
transforms: - type: increment target: myProperty # can be dot-separated path
To increment a value by a specific amount:
transforms: - type: increment target: myProperty # can be dot-separated path value: 10
decrement#
To decrement a value by 1:
transforms: - type: decrement target: myProperty # can be dot-separated path
To decrement a value by a specific amount:
transforms: - type: decrement target: myProperty # can be dot-separated path value: 10
concat#
@TODO
Conditions#
Each transform can also have its own set of conditions defined under the conditions
property. If the conditions are met, the individual transform will then be applied.