> ## Documentation Index
> Fetch the complete documentation index at: https://new.docs.falkordb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# map.fromPairs

> Converts a list of [key, value] pairs into a map.

## Description

Converts a list of key-value pairs into a map. Each pair should be a two-element array `[key, value]`.

## Syntax

```cypher theme={null}
flex.map.fromPairs(pairs)
```

## Parameters

| Parameter | Type | Required | Description                                                  |
| --------- | ---- | -------- | ------------------------------------------------------------ |
| `pairs`   | list | Yes      | A list of two-element arrays, each containing `[key, value]` |

## Returns

**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.

## Examples

### Example 1: Basic Conversion

```cypher theme={null}
WITH [['name', 'Alice'], ['age', 30], ['city', 'NYC']] AS pairs
RETURN flex.map.fromPairs(pairs) AS result
```

**Output:**

```text theme={null}
result
------------------------------------
{name: 'Alice', age: 30, city: 'NYC'}
```

### Example 2: Converting Zipped Data

```cypher theme={null}
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 user
```

**Output:**

```text theme={null}
user
------------------------------------------
{name: 'Bob', age: 25, email: 'bob@example.com'}
```

### Example 3: Dynamic Property Creation

```cypher theme={null}
MATCH (p:Product)
WITH collect([p.id, p.price]) AS pricePairs
RETURN flex.map.fromPairs(pricePairs) AS priceMap
```

### Example 4: Converting Query Results to Lookup Map

```cypher theme={null}
MATCH (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
```

## Notes

* 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 `null` or `undefined`, the pair is ignored
* Duplicate keys result in the last value being used
* Keys are converted to strings as map property names

## See Also

* [coll.zip](/udfs/flex/collections/zip) - Create pairs from two lists
* [map.submap](/udfs/flex/map/submap) - Extract subset of keys from a map

## Frequently Asked Questions

<AccordionGroup>
  <Accordion title="What format does flex.map.fromPairs expect?">
    It expects a list of two-element lists (pairs) where the first element is the key and the second is the value: `[['key1', 'val1'], ['key2', 'val2']]`.
  </Accordion>

  <Accordion title="What happens with duplicate keys in the pairs list?">
    Later pairs overwrite earlier ones — the last value for a given key wins.
  </Accordion>
</AccordionGroup>
