---
schema_version: "1"
id: 2e8dfece842e611816e5614572313220f8d83c76c5730639d67fa73f2004e087
title: readUrl
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.9/dw-core-functions-readurl.md
canonical_url: https://docs.mulesoft.com/dataweave/2.9/dw-core-functions-readurl
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 0ad41a26b836001fab7ee8f126800e1d061c90cf46bfccb797683a75b593f7b7
description: MuleSoft Documentation Site
release: "2.9"
latest: false
---
---
product: DataWeave
version: 2.9
---

# readUrl

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

## readUrl(url: String, contentType: String = "application/dw", readerProperties: Object = {}): Any

Reads a URL, including a classpath-based URL, and returns parsed content. This function works
similar to the `read` function.

The classpath-based URL uses the `classpath:` protocol prefix, for example:
`classpath://myfolder/myFile.txt` where `myFolder` is located under `src/main/resources` in a Mule
project. Other than the URL, `readURL` accepts the same arguments as `read`.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>url</code></p></td><td><p>The URL string to read. It also accepts a classpath-based URL.</p></td></tr><tr><td><p><code>contentType</code></p></td><td><p>A supported format (or MIME type). Default: <code>application/dw</code>.</p></td></tr><tr><td><p><code>readerProperties</code></p></td><td><p>Optional: Sets reader configuration properties. For other formats and reader configuration properties, see <a href="https://docs.mulesoft.com/dataweave/latest/dataweave-formats">Supported Data Formats</a>.</p></td></tr></tbody></table>

### Example

This example reads a JSON object from a URL. (For readability, the output values shown below are
shortened with `…​`.)

#### Source

```DataWeave
%dw 2.0
output application/json
---
readUrl("https://jsonplaceholder.typicode.com/posts/1", "application/json")
```

#### Output

```JSON
{ "userId": 1, "id": 1, "title": "sunt aut ...", "body": "quia et ..." }
```

### Example

This example reads a JSON object from a `myJsonSnippet.json` file located in the
`src/main/resources` directory in Studio. (Sample JSON content for that file is shown in the Input
section below.) After reading the file contents, the script transforms selected fields from JSON to
CSV. Reading files in this way can be useful when trying out a DataWeave script on sample data,
especially when the source data is large and your script is complex.

#### Source

```DataWeave
%dw 2.0
var myJsonSnippet = readUrl("classpath://myJsonSnippet.json", "application/json")
output application/csv
---
(myJsonSnippet.results map(item) -> item.profile)
```

#### Input

```JSON
{
  "results": [
    {
      "profile": {
        "firstName": "john",
        "lastName": "doe",
        "email": "johndoe@demo.com"
      },
      "data": {
        "interests": [
          {
            "language": "English",
            "tags": [
              "digital-strategy:Digital Strategy",
              "innovation:Innovation"
            ],
            "contenttypes": []
          }
        ]
      }
    },
    {
      "profile": {
      "firstName": "jane",
        "lastName": "doe",
        "email": "janedoe@demo.com"
      },
      "data": {
        "interests": [
          {
            "language": "English",
            "tags": [
              "tax-reform:Tax Reform",
              "retail-health:Retail Health"
            ],
            "contenttypes": [
              "News",
              "Analysis",
              "Case studies",
              "Press releases"
            ]
          }
        ]
      }
    }
  ]
}
```

#### Output

```CSV
firstName,lastName,email
john,doe,johndoe@demo.com
jane,doe,janedoe@demo.com
```

### Example

This example reads a CSV file from a URL, sets reader properties to indicate that there’s no header,
and then transforms the data to JSON.

#### Source

```DataWeave
%dw 2.0
output application/json
---
readUrl("https://mywebsite.com/data.csv", "application/csv", {"header" : false})
```

#### Input

Max,the Mule,MuleSoft

#### Output

```JSON
[
 {
   "column_0": "Max",
   "column_1": "the Mule",
   "column_2": "MuleSoft"
 }
]
```

### Example

This example reads a simple `dwl` file from the `src/main/resources` directory in Studio, then
dynamically reads the value of the key `name` from it. (Sample content for the input file is shown
in the Input section below.)

#### Source

```DataWeave
%dw 2.0
output application/json
---
(readUrl("classpath://name.dwl", "application/dw")).firstName
```

#### Input

```JSON
{
  "firstName" : "Somebody",
  "lastName" : "Special"
}
```

#### Output

```CSV
"Somebody"
```
