API Reference - Transformation Utils

The Utils class in Transformations provides a few convenience functions.

isArray(object: value) - boolean

Detects if a python object is an array. Returns True if it is.

from io.hevo.api import Event
from io.hevo.api import Utils

def transform(event):
    eventName = event.getEventName()
    properties = event.getProperties()
    
    is_field_array = Utils.isArray(properties('field_name'))
        ...

convertToArray(object: value) - [object]

Converts an object into an array if it is a valid array

from io.hevo.api import Event
from io.hevo.api import Utils

def transform(event):
    eventName = event.getEventName()
    properties = event.getProperties()
    
    field_as_array = Utils.convertToArray(properties('field_name'))
    for i in range(len(field_as_array)):
        elem = array[i]
        ...

isDict(object: value) - boolean

Detects if a python object is a dictionary. Returns True if it is.

from io.hevo.api import Event
from io.hevo.api import Utils

def transform(event):
    eventName = event.getEventName()
    properties = event.getProperties()
    
    is_field_a_dict = Utils.isDict(properties('field_name'))
        ... 

getType(object: value) - string

Returns type of object.

from io.hevo.api import Event
from io.hevo.api import Utils

def transform(event):
    eventName = event.getEventName()
    properties = event.getProperties()
    
    someNumber = 10
    properties['type'] = Utils.getType(someNumber)
        ...

properties['type'] = int

replaceUnicode( string: onString, string: replacement ) - string

Returns onString with all unicode characters replaced with replacement

from io.hevo.api import Event
from io.hevo.api import Utils

def transform(event):
    eventName = event.getEventName()
    properties = event.getProperties()
    
    withUnicode = properties['stringWithUnicode']
    properties['withoutUnicode'] = Utils.replaceUnicode(withUnicode," ")
        ...

properties['withoutUnicode'] will have a space in place of every unicode character

trimUnicode( string: onString ) - string

Returns onString with all unicode characters omitted.

from io.hevo.api import Event
from io.hevo.api import Utils

def transform(event):
    eventName = event.getEventName()
    properties = event.getProperties()
    
    withUnicode = properties['stringWithUnicode']
    properties['withoutUnicode'] = Utils.trimUnicode(withUnicode)
        ...

properties['withoutUnicode'] will not have any unicode characters.

jsonStringToDict( string: json ) - dict

Converts any json string json to a python dictionary

from io.hevo.api import Event
from io.hevo.api import Utils

def transform(event):
    eventName = event.getEventName()
    properties = event.getProperties()
    
    jsonString = "{\"City\":\"bangalore\"}"
    jsonDict = Utils.jsonStringToDict(jsonString)
        ...

jsonDict = {\"City\":\"Bangalore\"}

dictToJsonString( dict: dictionary ) - dict

Converts python dictionary to a string.

from io.hevo.api import Event
from io.hevo.api import Utils

def transform(event):
    eventName = event.getEventName()
    properties = event.getProperties()
    
    dictionary = {"India": "Delhi", "China": "Beijing"} # JsonObject from a source table
    jsonStr = Utils.dictToJsonString(dictionary)
        ...

jsonStr = "{\"India\":\"Delhi\",\"China\":\"Beijing\"}"