SORT

Sorts elements in an array by a property of an element in the array (case-sensitive). Pass a dot-separated path to sort by nested keys.

Syntax 

SORT(array, path, [include_json_paths: FALSE])

Usage examples 

Example 1

Input

1
{
2
"my_action": {
3
"message": [
4
"north",
5
"South",
6
"east",
7
"west"
8
]
9
}
10
}

Formula

SORT(my_action.message)

Output

1
[
2
"South",
3
"east",
4
"north",
5
"west"
6
]

Example 2

Sorts by key

Input

1
{
2
"animals": [
3
{
4
"name": "Dog"
5
},
6
{
7
"name": "Cat"
8
},
9
{
10
"name": "Bear"
11
}
12
]
13
}

Formula

SORT(animals, 'name')

Output

1
[
2
{
3
"name": "Bear"
4
},
5
{
6
"name": "Cat"
7
},
8
{
9
"name": "Dog"
10
}
11
]

Example 3

Sorts by nested key

Input

1
{
2
"employees": [
3
{
4
"name": "Jim",
5
"address": {
6
"city": "New York"
7
}
8
},
9
{
10
"name": "John",
11
"address": {
12
"city": "Dublin"
13
}
14
},
15
{
16
"name": "Jane",
17
"address": {
18
"city": "London"
19
}
20
}
21
]
22
}

Formula

SORT(employees, 'address.city', include_json_paths: TRUE)

Output

1
[
2
{
3
"name": "John",
4
"address": {
5
"city": "Dublin"
6
}
7
},
8
{
9
"name": "Jane",
10
"address": {
11
"city": "London"
12
}
13
},
14
{
15
"name": "Jim",
16
"address": {
17
"city": "New York"
18