Skip to main content

Array Functions

The following is the sample JSON for all the examples

data = {
"company_name": "Nakatomi Trading Corp",
"total_amount": 82542.56,
"date": "2021-09-30",
"items": [
{
"name": "Brand Guide",
"man_hour": 2,
"unit": "hour",
"unit_price": 120.0,
"item_total": 240.0
},
{
"name": "Software Development",
"man_hour": 17,
"unit": "hour",
"unit_price": 20.0,
"item_total": 340.0
},
{
"name": "Landing Page Design",
"man_hour": 5,
"unit": "hour",
"unit_price": 20.0,
"item_total": 80.0
}

]
}

asArray

It extracts the field of an array and returns a one-dimensional array.

Usage

asArray(`field`, `array`)

Parameters

ParameterTypeDescription
fieldstringProperty name of the an object in an array
arrayarray

Example

{{ asArray("name", data.items) }}

Output

["Brand Guide", "Software Development","Landing Page Design"]

sort

It sorts the array based on the field

Usage

sort(`field`, `array`, `direction`)

Parameters

ParameterTypeDescription
fieldstringProperty name of the an object in an array
arrayarrayAn array
directionstringDirection of sorting, options are asc and desc

(Use comma(,) for multiple property names or directions)

Example 1: Simple an array with a single property

{{ sort("man_hours", data.items,"asc")}}

Output

[
{
"name": "Brand Guide",
"man_hour": 2,
"unit": "hour",
"unit_price": 120.0,
"item_total": 240.0
},
{
"name": "Landing Page Design",
"man_hour": 5,
"unit": "hour",
"unit_price": 20.0,
"item_total": 80.0
}

{
"name": "Software Development",
"man_hour": 17,
"unit": "hour",
"unit_price": 20.0,
"item_total": 340.0
}
]

Example 2: Sort an array with multiple columns

{{ sort("man_hour,unit_price", data.items,"asc,desc")}}

fieldsToRows

The function extracts values from the object for each field, splitting them based on the delimiter. The function then returns an array of objects, where each object represents a row of data, with the extracted values assigned to their respective fields.

Usage

fieldsToRows(`obj`, `fields`, `delimitor`)

Parameters

ParameterTypeDescription
objobjectAn object
fieldsarrayFields of the object
delimiterstringDelimiter, default to

Example

{{ fieldsToRows(data, ["Date","Location","Rate"],"asc")}}

Input data

{
"Date": "2026-12-01|2026-12-02|2026-12-03",
"Location": "US|US|SG",
"Rate": "1.2|5|3"
}

Output

[
{
"Date": "2026-12-01",
"Location": "US",
"Rate": "1.2"
},
{
"Date": "2026-12-02",
"Location": "US",
"Rate": "5"
},
{
"Date": "2026-12-03",
"Location": "SG",
"Rate": "3"
}
]

distinctArray

This function return all unique values in a array

Usage

distinctArray(`array`)

Parameters

ParameterTypeDescription
arrayarrayarray

Example

{{ distinctArray([1,1,2,2,3]) }}

Output

[1,2,3]