---
schema_version: "1"
id: 8e208fcf05f8950f1fa61f04f3845af532c6ca6950c000e1301689c5559a4b86
title: Look Up Data in a CSV File
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.6/dataweave-cookbook-csv-lookup.md
canonical_url: https://docs.mulesoft.com/dataweave/2.6/dataweave-cookbook-csv-lookup
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 9ac2d793c436e5cb3f2fa592077541d48ccf5e2ceec219c33ecdec66e7d64953
description: MuleSoft Documentation Site
release: "2.6"
latest: false
---
---
product: DataWeave
version: 2.6
---

# Look Up Data in a CSV File

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

This DataWeave example uses `filter` with `map` to look up data in a CSV file and return a country
code for each calling code found within an input array of phone numbers.

The following JSON payload provides an array of phone numbers to the DataWeave script.

```JSON
[
   "54-112724555",
   "1-6298765432"
]
```

The value of the Mule variable `country_codes` is a CSV file that maps calling codes to country
codes.

```CSV
CALLING_CODE,COUNTRY_CODE
1,US
7,RU
54,AR
20,EG
32,BE
33,FR
505,NI
506,CR
1876,JM
1905,CA
1939,PR
262262,RE
262269,YT
.,.
.,.
```

The following DataWeave script reads each phone number in the payload and uses the `filter` function
to search for the calling code within the Mule variable `country_code` that matches the calling code
in the phone number. Then the `map` function gets the country code that corresponds to the calling
code and returns the results to an array of JSON objects.

DataWeave Script:

```dataweave
%dw 2.0
output application/json

fun lookupCountryCode(phoneNumber: String): String = do {
    var callingCode = (phoneNumber splitBy("-"))[0]
    ---
    (vars.country_code filter ((item, index) -> item.CALLING_CODE == callingCode) map ((item, index) -> item.COUNTRY_CODE))[0]
}
---
payload map ((item, index) -> { phone: item, countryCode: lookupCountryCode(item)})
```

Sample Output (JSON):

```JSON
[
  {
    "phone": "54-112724555",
    "countryCode": "AR"
  },
  {
    "phone": "1-6298765432",
    "countryCode": "US"
  }
]
```

## See Also

- [Supported Data Formats](https://docs.mulesoft.com/dataweave/2.6/dataweave-formats)
