| layout | title | parent | grand_parent |
|---|---|---|---|
default |
map.fromPairs |
Map Functions |
FLEX Function Reference |
Converts a list of key-value pairs into a map. Each pair should be a two-element array [key, value].
flex.map.fromPairs(pairs)| Parameter | Type | Required | Description |
|---|---|---|---|
pairs |
list | Yes | A list of two-element arrays, each containing [key, value] |
Type: map (object)
A map where each key-value pair from the input list becomes a property. Returns an empty map if input is not an array.
WITH [['name', 'Alice'], ['age', 30], ['city', 'NYC']] AS pairs
RETURN flex.map.fromPairs(pairs) AS resultOutput:
result
------------------------------------
{name: 'Alice', age: 30, city: 'NYC'}
WITH ['name', 'age', 'email'] AS keys,
['Bob', 25, 'bob@example.com'] AS values
WITH flex.coll.zip(keys, values) AS pairs
RETURN flex.map.fromPairs(pairs) AS userOutput:
user
------------------------------------------
{name: 'Bob', age: 25, email: 'bob@example.com'}
MATCH (p:Product)
WITH collect([p.id, p.price]) AS pricePairs
RETURN flex.map.fromPairs(pricePairs) AS priceMapMATCH (c:Country)
WITH collect([c.code, c.name]) AS countryPairs
WITH flex.map.fromPairs(countryPairs) AS lookup
RETURN lookup['US'] AS usaName, lookup['UK'] AS ukName- Returns empty map if input is not an array or is
null - Each pair must be a two-element array; invalid pairs are skipped
- If a key is
nullorundefined, the pair is ignored - Duplicate keys result in the last value being used
- Keys are converted to strings as map property names
- coll.zip - Create pairs from two lists
- map.submap - Extract subset of keys from a map