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

# update

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

## update(Object, String): Any

This `update` function updates a field in an object with the specified string value.

The function returns a new object with the specified field and value.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>objectValue</code></p></td><td><p>The object to update.</p></td></tr><tr><td><p><code>fieldName</code></p></td><td><p>A string that provides the name of the field.</p></td></tr></tbody></table>

### Example

This example updates the `name` field in the object `{name: "Mariano"}` with the specified value.

#### Source

```DataWeave
%dw 2.0
import * from dw::util::Values
output application/json
---
{name: "Mariano"} update "name" with "Data Weave"
```

#### Output

```Json
{
  "name": "Data Weave"
}
```

## update(Object, PathElement): Any

This `update` function updates an object field with the specified `PathElement` value.

The function returns a new object with the specified field and value.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>objectValue</code></p></td><td><p>The object to update.</p></td></tr><tr><td><p><code>fieldName</code></p></td><td><p>A <code>PathElement</code> that specifies the field name.</p></td></tr></tbody></table>

### Example

This example updates the value of a `name` field in the object `{name: "Mariano"}`. It uses
`field("name")` to return the `PathElement` that it passes to `update`. It uses `with "Data Weave"`
to specify the value (`Data Weave`) of `name`.

#### Source

```DataWeave
%dw 2.0
import * from dw::util::Values
output application/json
---
{name: "Mariano"} update field("name") with "Data Weave"
```

#### Output

```Json
{
  "name": "Data Weave"
}
```

## update(Array, Number): Any

Updates an array index with the specified value.

This `update` function returns a new array that changes the value of the specified index.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p>objectValue</p></td><td><p>The array to update.</p></td></tr><tr><td><p>indexToUpdate</p></td><td><p>The index of the array to update. The index must be a number.</p></td></tr></tbody></table>

### Example

This example replaces the value `2` (the index is `1`) with `5` in the the input array `[1,2,3]`.

#### Source

```DataWeave
%dw 2.0
import * from dw::util::Values
output application/json
---
[1,2,3] update 1 with 5
```

#### Output

```Json
[
   1,
   5,
   3
 ]
```

## update(Array, String): Any

This `update` function updates all objects within the specified array with the given string value.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>objectValue</code></p></td><td><p>The array of objects to update.</p></td></tr><tr><td><p><code>indexToUpdate</code></p></td><td><p>A string providing the name of the field to update.</p></td></tr></tbody></table>

### Example

This example updates value of the `role` fields in the array of objects.

#### Source

```DataWeave
%dw 2.0
import * from dw::util::Values
output application/json
---
[{role: "a", name: "spiderman"}, {role: "b", name: "batman"}] update "role" with "Super Hero"
```

#### Output

```Json
[{
   "role": "Super Hero",
   "name": "spiderman"
 },
 {
   "role": "Super Hero",
   "name": "batman"
}]
```

## update(Array, PathElement): Any

This `update` function updates the specified index of an array with the given `PathElement` value.

The function returns a new array that contains given value at the specified index.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>objectValue</code></p></td><td><p>The array to update.</p></td></tr><tr><td><p><code>indexToUpdate</code></p></td><td><p>The index of the array to update. The index must be specified as a <code>PathElement</code>.</p></td></tr></tbody></table>

### Example

This example updates the value of an element in the input array. Notice that it uses `index(1)` to
return the index as a `PathElement`, which it passes to `update`. It replaces the value `2` at that
index with `5`.

#### Source

```DataWeave
%dw 2.0
import * from dw::util::Values
output application/json
---
[1,2,3] update index(1) with 5
```

#### Output

```Json
[
   1,
   5,
   3
 ]
```

## update(Array | Object | Null, Array<String | Number | PathElement>): Any

Updates the value at the specified path with the given value.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>objectValue</code></p></td><td><p>The value to update. Accepts an array, object, or null value.</p></td></tr><tr><td><p><code>path</code></p></td><td><p>The path to update. The path must be an array of strings, numbers, or `PathElement`s.</p></td></tr></tbody></table>

### Example

This example updates the name of the user.

#### Source

```DataWeave
%dw 2.0
import * from dw::util::Values
output application/json
---
{user: {name: "Mariano"}} update ["user", field("name")] with "Data Weave"
```

#### Output

```Json
{
   "user": {
     "name": "Data Weave"
   }
 }
```

## update(Null, Number | String | PathElement): Any

Helper function that enables `update` to work with a `null` value.
