Array functions

This page describes the additional set of predefined Jsonnet functions for the Data Transformer Script task available in Application Integration.

Before you begin

To use the following predefined functions, you must import the functions library in your script. Importing the functions library lets you use both the standard Jsonnet functions and the predefined Data Transformer functions.

Application Integration supports Jsonnet functions library v0.20.0. For information about the Jsonnet standard functions, see Jsonnet Standard Library.

Average

Syntax
        
avg(arr)
      
Description Calculates the numerical average of all the values in an array.
Input parameter arr: The input array.
Return type DOUBLE
Output Returns the average of all the values in the array.

Contains

Syntax
        
contains(arr, elem)
      
Description Checks the occurrence of the specified element in an array.
Input parameter arr: The input array.

elem: The array element to search.

Return type BOOLEAN
Output Returns TRUE if a match is found and FALSE otherwise.

Max Array

Syntax
        
maxArray(arr)
      
Description Finds the highest value in an array.
Input parameter arr: The input array.
Return type The data type of the input array.
Output Returns the highest value found in the array.

Min Array

Syntax
        
minArray(arr)
      
Description Finds the lowest value in an array.
Input parameter arr: The input array.
Return type The data type of the input array.
Output Returns the lowest value found in the array.

Remove

Syntax
        
remove(arr, elem)
      
Description Removes the specified element from an array.
Input parameter arr: The input array.

elem: The array element to remove.

Return type The data type of the input array.
Output Returns the updated array after removing the specified element.

Remove At

Syntax
        
removeAt(arr, index)
      
Description Removes an element from an array at the specified index.
Input parameter arr: The input array.

index: The array index of the element to remove.

Return type The data type of the input array.
Output Returns the updated array after removing the specified element.

Sum

Syntax
        
sum(arr)
      
Description Adds all the values in an array.
Input parameter arr: The input array.
Return type The data type of the input array.
Output Returns the sum of all the elements in the array.

GroupBy

Syntax
        
groupBy(array, function)
      
Description Creates an object composed of keys generated from the results of running each element of array through the iteratee function. For example, f.groupBy([1,1.3,1.8],std.floor) would generate {"1": [1,1.3,1.8]}.
Input parameter
  • array: The collection that the method iterates over.

    function: The function that is invoked for every element in the array.

Return type JSON
Output Returns the composed aggregate object.

Zip

Syntax
        
zip([arrays])
      
Description It create an array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second element of the given arrays, and so on. For example, f.zip([[1, "one", "I"],[2, "two", "II"],[3, "three", "III"]]) would generate [[1,2,3],["one", "two", "three"],["I", "II", "III"]].
Input parameter [arrays]: This parameter holds the arrays to process.
Return type array
Output Returns the new array of regrouped elements.

Unzip

Syntax
        
unzip(array)
      
Description It creates an array of grouped elements. Accepts an array of grouped elements and also creates an array regrouping the elements to their pre-zip configuration. For example, f.unzip([[1, "one", "I"],[2, "two", "II"],[3, "three", "III"]]) would generate [[1,2,3],["one", "two", "three"],["I", "II", "III"]].
Input parameter array: This parameter holds the array of grouped elements to process.
Return type array
Output Returns the new array of regrouped elements.

Recommendation