Array
array uniquearray uniquearray mergearray mergearray mergearray slicearray slicearray splicearray splicearray chunkarray reversearray padarray fillarray rangearray rangearray columnarray columnarray combinearray fliparray keysarray keysarray keysarray valuesarray diffarray diffarray intersectarray intersectarray searcharray searcharray containsarray containsarray count_valuesarray sortarray sortarray ksortarray ksortarray shufflearray shufflearray sumarray productarray firstarray lastarray flattenarray flattenarray group_byarray index_byarray fill_keysarray is_list

array unique <json_array>


Description

    Remove the duplicate values (the first one is kept, an object keeps its keys)

Parameters

    json_array:   The array - String - required
admin
array unique "[3, 1, 3, \"a\", 1.0, \"a\", \"1\"]"
mentdb
[3, 1, "a", "1"]

array unique <json_array> <json_params>


Description

    Remove the duplicates with parameters: loose (the numbers written as text equal the numbers)

Parameters

    json_array:   The array - String - required
    json_params:   The parameters - String - required
admin
array unique "[1, \"1\", 1.0, 2]" "{\"loose\": true}"
mentdb
[1, 2]
Used in use cases (2 recipes)

    JSON & document store developer › Work on arrays without loops: column, unique, group_by, sort by field, sum, slice
    Web & API developer › Clean the links of a page: parse, resolve the relative links, normalize to remove duplicates
Often used with

    array column  ·  array group_by  ·  array intersect  ·  array keys  ·  array slice  ·  array sort  ·  array sum  ·  json doc

array merge <json_array1> <json_array2>


Description

    Merge two arrays: lists are appended; for objects the text keys of the second array win and the integer keys are renumbered (PHP array_merge)

Parameters

    json_array1:   The first array - String - required
    json_array2:   The second array - String - required
admin
array merge "[1, 2]" "[2, 3]"
mentdb
[1, 2, 2, 3]
Objects (configuration with overrides)
admin
array merge "{\"host\": \"localhost\", \"port\": 3306}" "{\"port\": 3307, \"user\": \"etl\"}"
mentdb
{"host": "localhost", "port": 3307, "user": "etl"}

array merge <json_array1> <json_array2> <json_array3>


Description

    Merge three arrays

Parameters

    json_array1:   The first array - String - required
    json_array2:   The second array - String - required
    json_array3:   The third array - String - required
admin
array merge "[\"a\"]" "[\"b\"]" "[\"c\", \"d\"]"
mentdb
["a", "b", "c", "d"]

array merge <json_array1> <json_array2> <json_array3> <json_array4>


Description

    Merge four arrays

Parameters

    json_array1:   The first array - String - required
    json_array2:   The second array - String - required
    json_array3:   The third array - String - required
    json_array4:   The fourth array - String - required
admin
array merge "[1]" "[2]" "[3]" "[4]"
mentdb
[1, 2, 3, 4]

array slice <json_array> <offset>


Description

    The elements from an offset to the end (a negative offset counts from the end)

Parameters

    json_array:   The array - String - required
    offset:   The offset (0 = first) - Number - required
admin
array slice "[\"a\", \"b\", \"c\", \"d\", \"e\"]" -2
mentdb
["d", "e"]

array slice <json_array> <offset> <length>


Description

    A part of the array: length elements from the offset (a negative length stops before the end)

Parameters

    json_array:   The array - String - required
    offset:   The offset - Number - required
    length:   The number of elements - Number - required
admin
array slice "[\"a\", \"b\", \"c\", \"d\", \"e\"]" 1 3
mentdb
["b", "c", "d"]
Without the first and the last
admin
array slice "[\"a\", \"b\", \"c\", \"d\", \"e\"]" 1 -1
mentdb
["b", "c", "d"]
Used in use cases (1 recipe)

    JSON & document store developer › Work on arrays without loops: column, unique, group_by, sort by field, sum, slice
Often used with

    array column  ·  array group_by  ·  array intersect  ·  array keys  ·  array sort  ·  array sum  ·  array unique

array splice <json_array> <offset> <length>


Description

    Remove a part of a list: the result and the removed elements

Parameters

    json_array:   The array - String - required
    offset:   The offset - Number - required
    length:   The number of elements to remove - Number - required
admin
array splice "[1, 2, 3, 4, 5]" 1 2
mentdb
{"result": [1, 4, 5], "removed": [2, 3]}

array splice <json_array> <offset> <length> <json_replacement>


Description

    Replace a part of a list by other elements (a JSON array, the values of a JSON object as PHP, or one value)

Parameters

    json_array:   The array - String - required
    offset:   The offset - Number - required
    length:   The number of elements to remove - Number - required
    json_replacement:   The new elements - String - required
admin
array splice "[1, 2, 3, 4, 5]" 1 2 "[\"x\", \"y\", \"z\"]"
mentdb
{"result": [1, "x", "y", "z", 4, 5], "removed": [2, 3]}

array chunk <json_array> <size>


Description

    Split a list into chunks of a size (batches)

Parameters

    json_array:   The array - String - required
    size:   The size of each chunk - Number - required
admin
array chunk "[1, 2, 3, 4, 5, 6, 7]" 3
mentdb
[[1, 2, 3], [4, 5, 6], [7]]

array reverse <json_array>


Description

    Reverse the order (an object keeps its keys)

Parameters

    json_array:   The array - String - required
admin
array reverse "[1, 2, 3]"
mentdb
[3, 2, 1]

array pad <json_array> <size> <value>


Description

    Pad a list to a size with a value (a negative size pads on the left)

Parameters

    json_array:   The array - String - required
    size:   The size - Number - required
    value:   The value - String - required
admin
array pad "[1, 2]" 5 0
mentdb
[1, 2, 0, 0, 0]
On the left
admin
array pad "[1, 2]" -4 "\"-\""
mentdb
["-", "-", 1, 2]

array fill <start> <count> <value>


Description

    An array of count times a value, with the keys start, start+1... (a list when start is 0)

Parameters

    start:   The first key - Number - required
    count:   The number of elements - Number - required
    value:   The value - String - required
admin
array fill 0 3 "\"n/a\""
mentdb
["n/a", "n/a", "n/a"]
From the key 5
admin
array fill 5 2 0
mentdb
{"5": 0, "6": 0}

array range <start> <end>


Description

    A list from start to end with a step of 1 (decreasing when start > end); numbers or single letters

Parameters

    start:   The start - String - required
    end:   The end - String - required
admin
array range 1 5
mentdb
[1, 2, 3, 4, 5]
Letters
admin
array range "a" "f"
mentdb
["a", "b", "c", "d", "e", "f"]

array range <start> <end> <step>


Description

    A list from start to end with a step (1 000 000 elements at most); the integers stay exact beyond the 64-bit range (PHP switches to floats)

Parameters

    start:   The start - String - required
    end:   The end - String - required
    step:   The step (positive) - Number - required
admin
array range 0 100 25
mentdb
[0, 25, 50, 75, 100]
Decimal step
admin
array range 0 1 0.25
mentdb
[0, 0.25, 0.5, 0.75, 1]

array column <json_rows> <field>


Description

    The values of a field of the rows (rows without the field are skipped)

Parameters

    json_rows:   The rows (array of objects) - String - required
    field:   The field ("" = the whole row) - String - required
admin
array column "[{\"id\": 3, \"name\": \"Dupont\", \"city\": \"Lyon\"}, {\"id\": 5, \"name\": \"Martin\", \"city\": \"Paris\"}, {\"id\": 7, \"name\": \"Payet\", \"city\": \"Lyon\"}]" "name"
mentdb
["Dupont", "Martin", "Payet"]

array column <json_rows> <field> <index_field>


Description

    The values of a field indexed by another field (a row without that field gets the next free integer key, as PHP)

Parameters

    json_rows:   The rows - String - required
    field:   The field ("" = the whole row) - String - required
    index_field:   The field giving the keys - String - required
admin
array column "[{\"id\": 3, \"name\": \"Dupont\", \"city\": \"Lyon\"}, {\"id\": 5, \"name\": \"Martin\", \"city\": \"Paris\"}, {\"id\": 7, \"name\": \"Payet\", \"city\": \"Lyon\"}]" "name" "id"
mentdb
{"3": "Dupont", "5": "Martin", "7": "Payet"}
The rows indexed by id
admin
array column "[{\"id\": 3, \"name\": \"Dupont\", \"city\": \"Lyon\"}, {\"id\": 5, \"name\": \"Martin\", \"city\": \"Paris\"}, {\"id\": 7, \"name\": \"Payet\", \"city\": \"Lyon\"}]" "" "id"
mentdb
{"3": {"id": 3, "name": "Dupont", "city": "Lyon"}, "5": {"id": 5, "name": "Martin", "city": "Paris"}, "7": {"id": 7, "name": "Payet", "city": "Lyon"}}
Used in use cases (3 recipes)

    JSON & document store developer › Work on arrays without loops: column, unique, group_by, sort by field, sum, slice
    Files & archives manager › Export a table to Parquet for the analytics tools, then check the file
    JSON & document store developer › Find the closest answer by meaning: cut, embed, search
Often used with

    array group_by  ·  array intersect  ·  array keys  ·  array slice  ·  array sort  ·  array sum  ·  array unique  ·  equal

array combine <json_keys> <json_values>


Description

    An object from a list of keys and a list of values

Parameters

    json_keys:   The keys - String - required
    json_values:   The values - String - required
admin
array combine "[\"code\", \"label\", \"rate\"]" "[\"S\", \"Standard\", 20]"
mentdb
{"code": "S", "label": "Standard", "rate": 20}

array flip <json_array>


Description

    Exchange the keys and the values (the values must be texts or numbers); a repeated value keeps its first position with the last key, as PHP

Parameters

    json_array:   The array - String - required
admin
array flip "{\"FR\": \"France\", \"RE\": \"La Réunion\"}"
mentdb
{"France": "FR", "La Réunion": "RE"}
A list gives the position of each value
admin
array flip "[\"a\", \"b\", \"c\"]"
mentdb
{"a": 0, "b": 1, "c": 2}

array keys <json_array>


Description

    The keys (the positions of a list)

Parameters

    json_array:   The array - String - required
admin
array keys "{\"a\": 1, \"b\": 2, \"c\": 1}"
mentdb
["a", "b", "c"]

array keys <json_array> <value>


Description

    The keys of the elements equal to a value

Parameters

    json_array:   The array - String - required
    value:   The value searched - String - required
admin
array keys "{\"a\": 1, \"b\": 2, \"c\": 1}" 1
mentdb
["a", "c"]

array keys <json_array> <value> <json_params>


Description

    The keys of the elements equal to a value, with parameters: loose

Parameters

    json_array:   The array - String - required
    value:   The value searched - String - required
    json_params:   The parameters - String - required
admin
array keys "[1, \"1\", 2]" 1 "{\"loose\": true}"
mentdb
[0, 1]
Used in use cases (1 recipe)

    JSON & document store developer › Work on arrays without loops: column, unique, group_by, sort by field, sum, slice
Often used with

    array column  ·  array group_by  ·  array intersect  ·  array slice  ·  array sort  ·  array sum  ·  array unique

array values <json_array>


Description

    The values (an object becomes a list)

Parameters

    json_array:   The array - String - required
admin
array values "{\"a\": 1, \"b\": 2}"
mentdb
[1, 2]

array diff <json_array1> <json_array2>


Description

    The values of the first array that are not in the second one

Parameters

    json_array1:   The first array - String - required
    json_array2:   The second array - String - required
admin
array diff "[\"a\", \"b\", \"c\", \"d\"]" "[\"b\", \"d\"]"
mentdb
["a", "c"]

array diff <json_array1> <json_array2> <json_params>


Description

    Difference with parameters: mode values (default), keys (array_diff_key) or assoc (key and value, array_diff_assoc), loose

Parameters

    json_array1:   The first array - String - required
    json_array2:   The second array - String - required
    json_params:   The parameters - String - required
admin
array diff "{\"a\": 1, \"b\": 2, \"c\": 3}" "{\"a\": 1, \"b\": 5}" "{\"mode\": \"assoc\"}"
mentdb
{"b": 2, "c": 3}

array intersect <json_array1> <json_array2>


Description

    The values of the first array that are also in the second one

Parameters

    json_array1:   The first array - String - required
    json_array2:   The second array - String - required
admin
array intersect "[1, 2, 3, 4]" "[4, 2, 9]"
mentdb
[2, 4]

array intersect <json_array1> <json_array2> <json_params>


Description

    Intersection with parameters: mode values, keys or assoc, loose

Parameters

    json_array1:   The first array - String - required
    json_array2:   The second array - String - required
    json_params:   The parameters - String - required
admin
array intersect "{\"a\": 1, \"b\": 2, \"c\": 3}" "{\"a\": 0, \"c\": 0}" "{\"mode\": \"keys\"}"
mentdb
{"a": 1, "c": 3}
Used in use cases (1 recipe)

    JSON & document store developer › Work on arrays without loops: column, unique, group_by, sort by field, sum, slice
Often used with

    array column  ·  array group_by  ·  array keys  ·  array slice  ·  array sort  ·  array sum  ·  array unique

array contains <json_array> <value>


Description

    1 if the array contains the value, else 0 (PHP in_array)

Parameters

    json_array:   The array - String - required
    value:   The value - String - required
admin
array contains "[\"FR\", \"RE\", \"GP\"]" "RE"
mentdb
1

array contains <json_array> <value> <json_params>


Description

    Contains with parameters: loose

Parameters

    json_array:   The array - String - required
    value:   The value - String - required
    json_params:   The parameters - String - required
admin
array contains "[\"1\", \"2\"]" 2 "{\"loose\": true}"
mentdb
1

array count_values <json_array>


Description

    The number of times each value appears (texts and numbers)

Parameters

    json_array:   The array - String - required
admin
array count_values "[\"FR\", \"DE\", \"FR\", \"FR\", \"ES\"]"
mentdb
{"FR": 3, "DE": 1, "ES": 1}

array sort <json_array>


Description

    Sort the values: null, booleans, numbers by value, then texts; an object keeps its keys (PHP asort)

Parameters

    json_array:   The array - String - required
admin
array sort "[3, 1, 2.5, \"b\", \"a\"]"
mentdb
[1, 2.5, 3, "a", "b"]

array sort <json_array> <json_params>


Description

    Sort with parameters: order (asc or desc), by (fields of the objects: \"a desc, b\" or an array), natural (file2 before file10), case_insensitive, numeric (the numbers written as text by value)

Parameters

    json_array:   The array - String - required
    json_params:   The parameters - String - required
admin
array sort "[\"file10\", \"file2\", \"File1\"]" "{\"natural\": true, \"case_insensitive\": true}"
mentdb
["File1", "file2", "file10"]
Rows by city then name descending
admin
array sort "[{\"id\": 3, \"name\": \"Dupont\", \"city\": \"Lyon\"}, {\"id\": 5, \"name\": \"Martin\", \"city\": \"Paris\"}, {\"id\": 7, \"name\": \"Payet\", \"city\": \"Lyon\"}]" "{\"by\": \"city, name desc\"}"
mentdb
[{"id": 7, "name": "Payet", "city": "Lyon"}, {"id": 3, "name": "Dupont", "city": "Lyon"}, {"id": 5, "name": "Martin", "city": "Paris"}]
Used in use cases (1 recipe)

    JSON & document store developer › Work on arrays without loops: column, unique, group_by, sort by field, sum, slice
Often used with

    array column  ·  array group_by  ·  array intersect  ·  array keys  ·  array slice  ·  array sum  ·  array unique

array ksort <json_object>


Description

    Sort an object by its keys (integer keys by value, then the others)

Parameters

    json_object:   The object - String - required
admin
array ksort "{\"b\": 1, \"10\": 2, \"a\": 3, \"9\": 4}"
mentdb
{"9": 4, "10": 2, "a": 3, "b": 1}

array ksort <json_object> <json_params>


Description

    Sort by the keys with parameters: desc, natural

Parameters

    json_object:   The object - String - required
    json_params:   The parameters - String - required
admin
array ksort "{\"v2\": 1, \"v10\": 2, \"v1\": 3}" "{\"natural\": true}"
mentdb
{"v1": 3, "v2": 1, "v10": 2}

array shuffle <json_array>


Description

    Shuffle a list (secure random)

Parameters

    json_array:   The array - String - required
admin
-> "[s]" (array shuffle "[1, 2, 3, 4, 5]"); -> "[res]" (concat (array sum [s]) " " (array count_values [s])); [res]
mentdb
15 {"2": 1, "1": 1, "4": 1, "5": 1, "3": 1}

array shuffle <json_array> <seed>


Description

    Shuffle a list with a seed: the same seed gives the same order (reproducible samples)

Parameters

    json_array:   The array - String - required
    seed:   The seed (integer) - Number - required
admin
array shuffle "[1, 2, 3, 4, 5, 6]" 42
mentdb
[2, 1, 5, 6, 4, 3]

array sum <json_array>


Description

    The exact decimal sum of the numbers (0.1 + 0.2 = 0.3)

Parameters

    json_array:   The array of numbers - String - required
admin
array sum "[0.1, 0.2, 1250.5]"
mentdb
1250.8
Used in use cases (1 recipe)

    JSON & document store developer › Work on arrays without loops: column, unique, group_by, sort by field, sum, slice
Often used with

    array column  ·  array group_by  ·  array intersect  ·  array keys  ·  array slice  ·  array sort  ·  array unique

array product <json_array>


Description

    The exact product of the numbers

Parameters

    json_array:   The array of numbers - String - required
admin
array product "[1.05, 1.02, 0.98]"
mentdb
1.04958

array first <json_array>


Description

    The first value (null if empty)

Parameters

    json_array:   The array - String - required
admin
array first "[\"a\", \"b\"]"
mentdb
a

array last <json_array>


Description

    The last value (null if empty)

Parameters

    json_array:   The array - String - required
admin
array last "{\"a\": 1, \"b\": {\"k\": 2}}"
mentdb
{"k": 2}

array flatten <json_array>


Description

    Flatten the nested lists

Parameters

    json_array:   The array - String - required
admin
array flatten "[1, [2, [3, [4]]]]"
mentdb
[1, 2, 3, 4]

array flatten <json_array> <depth>


Description

    Flatten the nested lists up to a depth

Parameters

    json_array:   The array - String - required
    depth:   The depth - Number - required
admin
array flatten "[1, [2, [3, [4]]]]" 1
mentdb
[1, 2, [3, [4]]]

array group_by <json_rows> <field>


Description

    Group the rows by the value of a field: an object of arrays of rows

Parameters

    json_rows:   The rows - String - required
    field:   The field - String - required
admin
array group_by "[{\"id\": 3, \"name\": \"Dupont\", \"city\": \"Lyon\"}, {\"id\": 5, \"name\": \"Martin\", \"city\": \"Paris\"}, {\"id\": 7, \"name\": \"Payet\", \"city\": \"Lyon\"}]" "city"
mentdb
{"Lyon": [{"id": 3, "name": "Dupont", "city": "Lyon"}, {"id": 7, "name": "Payet", "city": "Lyon"}], "Paris": [{"id": 5, "name": "Martin", "city": "Paris"}]}
Used in use cases (1 recipe)

    JSON & document store developer › Work on arrays without loops: column, unique, group_by, sort by field, sum, slice
Often used with

    array column  ·  array intersect  ·  array keys  ·  array slice  ·  array sort  ·  array sum  ·  array unique

array index_by <json_rows> <field>


Description

    Index the rows by the value of a field (the last row wins)

Parameters

    json_rows:   The rows - String - required
    field:   The field - String - required
admin
array index_by "[{\"id\": 3, \"name\": \"Dupont\", \"city\": \"Lyon\"}, {\"id\": 5, \"name\": \"Martin\", \"city\": \"Paris\"}, {\"id\": 7, \"name\": \"Payet\", \"city\": \"Lyon\"}]" "id"
mentdb
{"3": {"id": 3, "name": "Dupont", "city": "Lyon"}, "5": {"id": 5, "name": "Martin", "city": "Paris"}, "7": {"id": 7, "name": "Payet", "city": "Lyon"}}

array fill_keys <json_keys> <value>


Description

    An object with the given keys and the same value

Parameters

    json_keys:   The keys - String - required
    value:   The value - String - required
admin
array fill_keys "[\"debit\", \"credit\"]" 0
mentdb
{"debit": 0, "credit": 0}

array is_list <json>


Description

    1 if the value is a list (a JSON array, or an object with the keys 0, 1, 2...), else 0

Parameters

    json:   The value - String - required
admin
array is_list "{\"0\": \"a\", \"1\": \"b\"}"
mentdb
1