Skip to content

Functions

The built-in functions are available to perform some of the common tasks.

TIP

quotedArguments config option is used to specify whether the string arguments should be quoted or not. By default, it is set to true.

Declaration

The hashtag token # is used as function declaration.

$.products[0].reviews.#avg()

Argument Spacing

Be careful with the spacing between the arguments.

Invalid:

  • $.users[0].name.#substring(1,2)
  • $.users[0].name.#substring(1, 2 )
  • $.users[0].name.#substring( 1, 2)
  • $.users[0].name.#substring(1 , 2)

Built-in Functions

NameCategoryReturnsDescriptionArguments
minNumeric ArrayNumberReturns the minimum value from the arraynone
maxNumeric ArrayNumberReturns the maximum value from the arraynone
avgNumeric ArrayNumberReturns the average value from the arraynone
sumNumeric ArrayNumberReturns the sum of the array elementsnone
countArrayNumberReturns the number of elements in the arraynone
sortArrayArrayReturns the sorted arraynone
reverseArrayArrayReturns the reversed arraynone
uniqueArrayArrayReturns the unique elements from the arraynone
containsStringBooleanReturns true if the string contains the specified substringString
lengthStringNumberReturns the length of the stringnone
substringStringStringReturns the substring from the stringNumber Number
upperStringStringUppercase the stringnone
lowerStringStringLowercase the stringnone
equalsStringBooleanReturns true if the two strings are equalString
isTrueBooleanBooleanCheck whether the value is truenone
isFalseBooleanBooleanCheck whether the value is falsenone

INFO

Category is the type of input that the function accepts


Sample Data

json
{
  "numbers": [1, 2, 3, 4, 5],
  "text": "Hello World",
  "array": ["apple", "banana", "apple", "orange"]
}

Queries

ts
// Get the minimum value from the numbers array
query.run("$.numbers.#min()") // 1

// Count the number of elements in the array
query.run("$.array.#count()") // 4

// Check whether the string contains "World"
query.run("$.text.#contains('World')") // true

// Get the substring from the string
query.run("$.text.#substring(0, 5)") // Hello