Skip to content

Arrays ​

sort, reverse, and distinct preserve the input type: sort(scores) on number[] infers number[].

For element-wise transformation and filtering, use the language constructs — -> projection and [predicate] filters — instead of JSONata's $map/$filter lambdas.

Measure ​

count ​

count(items: unknown[]): number

Number of elements.

typeflow
total: count(order.items)

Combine ​

join ​

join(items: string[], separator?: string): string

Concatenates the strings with a separator (default "").

typeflow
csv: join(user.tags, ", ")

append ​

append(first: unknown[], second: unknown[]): unknown[]

Concatenates two arrays.

typeflow
all: append(data.names, data.scores)

zip ​

zip(first: unknown[], second: unknown[]): unknown[][]

Pairs elements by index, truncated to the shorter array.

typeflow
paired: zip(data.names, data.scores)

Reorder ​

sort ​

sort(items: string[] | number[]): string[] | number[]

Sorts in natural ascending order; the result keeps the input type.

typeflow
ranked: sort(data.scores)

reverse ​

reverse(items: unknown[]): unknown[]

Reverses the order; the result keeps the input type.

typeflow
latestFirst: reverse(data.scores)

shuffle ​

shuffle(items: unknown[]): unknown[]

Random permutation; keeps the input type.

typeflow
deckOrder: shuffle(deck.cards)

Dedupe ​

distinct ​

distinct(items: unknown[]): unknown[]

Removes duplicates (deep equality for objects); keeps the input type.

typeflow
unique: distinct(data.names)

Playground ​

Mapping✔Playground ↗
Input JSON
Output
{
  "ranked": [
    12,
    12,
    7,
    3
  ],
  "unique": [
    "ada",
    "alan"
  ],
  "merged": [
    "ada",
    "alan",
    "ada",
    12,
    3,
    12,
    7
  ],
  "paired": [
    [
      "ada",
      12
    ],
    [
      "alan",
      3
    ],
    [
      "ada",
      12
    ]
  ],
  "csv": "ada, alan, ada"
}
inferred type{ ranked: number[]; unique: string[]; merged: (string | number)[]; paired: (string | number)[][]; csv: string; }

Released under the MIT License.