Transform Reference

Array Verbs

Array indexing, filtering, sorting, deduplication, and transformation.

VerbSyntaxDescriptionTry It
at%at @array indexGet element at index Try
filter%filter @array "condition"Filter by condition Try
flatten%flatten @arrayFlatten nested arrays Try
distinct%distinct @arrayUnique values only Try
sort%sort @arraySort ascending Try
sortBy%sortBy @array "field"Sort by field Try
reverse%reverse @arrayReverse order Try
reduce%reduce @array "verb" initialValueFold array to single value using named verb Try
pivot%pivot @array "keyField" "valueField"Array of objects to object keyed by field Try
unpivot%unpivot @object "keyName" "valueName"Object to array of {key, value} objects Try

Reference

Reduce (reduce) — Fold an Array

Applies a named verb cumulatively to array elements, reducing to a single value.

%reduce @array "verbName" initialValue

  • The verb must accept 2 arguments (accumulator, current element).
  • Compatible verbs: add, subtract, multiply, divide, concat, minOf, maxOf, and any custom 2-argument verb.
  • If the array is empty, returns the initial value.
  • Null elements are skipped.

Pivot (pivot) — Array to Object

Transforms an array of objects into a single object, using one field as keys and another as values.

%pivot @array "keyField" "valueField"

  • Each object in the array must have both fields. Objects missing either field are skipped.
  • If duplicate keys exist, the last value wins.
  • Key values are coerced to strings.
  • Returns null if input is not an array.

Example:

Input:  [{"k":"width","v":100}, {"k":"height","v":200}]
Output: {"width": 100, "height": 200}

Unpivot (unpivot) — Object to Array

Transforms an object into an array of {key, value} objects.

%unpivot @object "keyName" "valueName"

  • Each property of the input object becomes one element in the output array.
  • Field names in the output are controlled by the keyName and valueName parameters.
  • Property order follows the original object's key order.
  • Returns null if input is not an object.

Example:

Input:  {"width": 100, "height": 200}
Output: [{"name":"width","size":100}, {"name":"height","size":200}]

Examples

Array verb examples
second_vehicle = %at @vehicles ##1
active_coverages = %filter @coverages "@.status = 'active'"
unique_states = %distinct @addresses.state
by_premium = %sortBy @coverages "premium"

; Reduce — fold array with a verb
total = %reduce @prices "add" ##0                     ; sum all prices
product = %reduce @factors "multiply" ##1             ; multiply all

; Pivot — array of objects to keyed object
settings = %pivot @configs "key" "value"              ; [{key:"a",value:1}] -> {a:1}

; Unpivot — object to array of {key, value}
rows = %unpivot @dimensions "name" "size"             ; {w:100,h:200} -> [{name:"w",size:100},...]