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

# field

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

## 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 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 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(String, Any, String, 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--
```
