---
schema_version: "1"
id: 05b9795d7e8d409c46e675b74e3337d0a26af26f6ffc1645113ad0c551ad7522
title: field
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dw-multipart-functions-field.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dw-multipart-functions-field
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 45ce79bc62342d5ed5c6f68f2350ad8786f643676b611589a50f8d0c2066ed83
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
---

# field

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

## field(opts: {| name: String, value: Any, mime?: String, fileName?: String |}): MultipartPart

Creates a `MultipartPart` data structure using the specified part name, input content for the part,
format (or mime type), and optionally, file name.

This version of the `field` function accepts arguments as an array of objects that use the parameter
names as keys, for example:
`Multipart::field({name:"order",value: myOrder, mime: "application/json", fileName: "order.json"})`

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>opts</code></p></td><td><div><div><p>Array of objects that specifies:</p></div><div><ul><li><p>A unique <code>name</code> (required) for the <code>Content-Disposition</code> header of the part.</p></li><li><p>A <code>value</code> (required) for the content of the part.</p></li><li><p><code>mime</code> (optional for strings) for the mime type (for example, <code>application/json</code>) to apply to content within the part. This setting can be used to transform the input type, for example, from JSON to XML.</p></li><li><p>An optional <code>fileName</code> value that you can supply to the <code>filename</code> parameter in the part’s <code>Content-Disposition</code> header.</p></li></ul></div></div></td></tr></tbody></table>

### Example

This example creates a `Multipart` data structure that contains parts.

#### Source

```DataWeave
%dw 2.0
import dw::module::Multipart
output multipart/form-data
var firstPart = "content for my first part"
var secondPart = "content for my second part"
---
{
  parts: {
    part1: Multipart::field({name:"myFirstPart",value: firstPart}),
    part2: Multipart::field("mySecondPart", secondPart)
  }
}
```

#### Output

```json
------=_Part_320_1528378161.1542639222352
Content-Disposition: form-data; name="myFirstPart"
content for my first part
------=_Part_320_1528378161.1542639222352
Content-Disposition: form-data; name="mySecondPart"
content for my second part
------=_Part_320_1528378161.1542639222352--
```

### Example

This example produces two parts. The first part (named `order`) outputs content in JSON and provides
a file name for the part (`order.json`). The second (named `clients`) outputs content in XML and
does not provide a file name. Also notice that in this example you need to add the function’s
namespace to the function name, for example, `Multipart::field`.

#### Source

```DataWeave
%dw 2.0
import dw::module::Multipart
output multipart/form-data
var myOrder = [
  {
    order: 1,
    amount: 2
  },
  {
    order: 32,
    amount: 1
  }
]
var myClients = {
  clients: {
    client: {
      id: 1,
      name: "Mariano"
    },
    client: {
      id: 2,
      name: "Shoki"
    }
  }
}
---
{
  parts: {
    order: Multipart::field({name:"order",value: myOrder, mime: "application/json", fileName: "order.json"}),
    clients: Multipart::field({name:"clients", value: myClients, mime: "application/xml"})
  }
}
```

#### Output

```txt
------=_Part_8032_681891620.1542560124825
Content-Type: application/json
Content-Disposition: form-data; name="order"; filename="order.json"

[
  {
    "order": 1,
    "amount": 2
  },
  {
    "order": 32,
    "amount": 1
  }
]
------=_Part_8032_681891620.1542560124825
Content-Type: application/xml
Content-Disposition: form-data; name="clients"

<clients>
  <client>
    <id>1</id>
    <name>Mariano</name>
  </client>
  <client>
    <id>2</id>
    <name>Shoki</name>
  </client>
</clients>
------=_Part_8032_681891620.1542560124825--
```

## field(name: String, value: Any, mime: String = "", fileName: String = ""): MultipartPart

Creates a `MultipartPart` data structure using the specified part name, input content for the part,
format (or mime type), and optionally, file name.

This version of the `field` function accepts arguments in a comma-separated list, for example:

```txt
Multipart::field("order", myOrder,"application/json", "order.json")`
```

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>opts</code></p></td><td><div><div><p>A set of parameters that specify:</p></div><div><ul><li><p>A unique <code>name</code> (required) for the <code>Content-Disposition</code> header of the part.</p></li><li><p>A <code>value</code> (required) for the content of the part.</p></li><li><p><code>mime</code> (optional for strings) for the mime type (for example, <code>application/json</code>) to apply to content within the part. This type can be used to transform the input type.</p></li><li><p>An optional <code>fileName</code> value that you can supply to the <code>filename</code> parameter in the part’s <code>Content-Disposition</code> header.</p></li></ul></div></div></td></tr></tbody></table>

### Example

This example produces two parts. The first part (named `order`) outputs content in JSON and provides
a file name for the part (`order.json`). The second (named `clients`) outputs content in XML and
does not provide a file name. The only difference between this `field` example and the previous
`field` example is the way you pass in arguments to the method. Also notice that in this example you
need to add the function’s namespace to the function name, for example, `Multipart::field`.

#### Source

```DataWeave
%dw 2.0
import dw::module::Multipart
output multipart/form-data
var myOrder = [
  {
    order: 1,
    amount: 2
  },
  {
    order: 32,
    amount: 1
  }
]
var myClients = {
  clients: {
    client: {
      id: 1,
      name: "Mariano"
    },
    client: {
      id: 2,
      name: "Shoki"
    }
  }
}
---
{
  parts: {
    order: Multipart::field("order", myOrder, "application/json", "order.json"),
    clients: Multipart::field("clients", myClients, "application/xml")
  }
}
```

#### Output

```txt
------=_Part_4846_2022598837.1542560230901
Content-Type: application/json
Content-Disposition: form-data; name="order"; filename="order.json"

[
  {
    "order": 1,
    "amount": 2
  },
  {
    "order": 32,
    "amount": 1
  }
]
------=_Part_4846_2022598837.1542560230901
Content-Type: application/xml
Content-Disposition: form-data; name="clients"

<clients>
  <client>
    <id>1</id>
    <name>Mariano</name>
  </client>
  <client>
    <id>2</id>
    <name>Shoki</name>
  </client>
</clients>
------=_Part_4846_2022598837.1542560230901--
```
