%dw 2.0
import * from dw::util::Values
output application/json
---
{name: "Mariano"} update "name" with "Data Weave"
update
DataWeave 2.2 is compatible and bundled with Mule 4.2. Standard Support for Mule 4.2 ended on May 2, 2021, and this version of Mule will reach its End of Life on May 2, 2023, when Extended Support ends. Deployments of new applications to CloudHub that use this version of Mule are no longer allowed. Only in-place updates to applications are permitted. MuleSoft recommends that you upgrade to the latest version of Mule 4 that is in Standard Support so that your applications run with the latest fixes and security enhancements. |
update(Object, String): Any
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
Name | Description |
---|---|
|
The object to update. |
|
A |
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
.
update(Array, Number): Any
update(Array, String): Any
This update
function updates all objects within the specified array with
the given string value.
Parameters
Name | Description |
---|---|
|
The array of objects to update. |
|
A string providing the name of the field to update. |
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
Name | Description |
---|---|
|
The array to update. |
|
The index of the array to update. The index must be specified as a |
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
.