This module handles value modification in a simple and nice way.
Since Version: 2.2.2
Functions
attr
attr(Namespace | Null, String): PathElement
This functions creates a PathElement
that selects an Attribute.
Parameters
Name | Description |
---|---|
namespace? |
The namespace of the attribute to select. If not specified null value is set |
name |
The name of the attribute to select. |
Example
This shows how to create an attr with a given namespace.
Source
1
2
3
4
5
6
%dw 2.0
output application/json
import * from dw::util::Values
ns ns0 http://acme.com/fo
---
attr(ns0 , "myAttr")
Output
1
2
3
4
5
{
"kind": "Attribute",
"namespace": "http://acme.com/foo",
"selector": "myAttr"
}
field
field(Namespace | Null, String): PathElement
This functions creates a PathElement
that selects an Object field.
===== Parameters
Name | Description |
---|---|
namespace? |
The namespace of the field to select. If not specified null value is set |
name |
The name of the attribute to select. |
Example
This example shows how the field
behaves under different inputs.
Source
1
2
3
4
5
6
%dw 2.0
output application/json
import * from dw::util::Values
ns ns0 http://acme.com/foo
---
field(ns0 , "myAttr")
Output
1
2
3
4
5
{
"kind": "Object",
"namespace": "http://acme.com/foo",
"selector": "myAttr"
}
index
index(Number): PathElement
This functions creates a PathElement
that selects an Array element.
Parameters
Name | Description |
---|---|
index |
Example
This example shows how the index
behaves under different inputs.
Source
1
2
3
4
5
6
%dw 2.0
output application/json
import * from dw::util::Values
ns ns0 http://acme.com/foo
---
index(0)
Output
1
2
3
4
5
{
"kind": "Array",
"namespace": null,
"selector": 0
}
mask
mask(Null, String | Number | PathElement): Any
Helper function to make mask work with null correctly
mask(Any, PathElement): Any
The mask function allows to replace all simple elements that matches the specified criteria. Simple elements are the ones that don’t have child elements, so when the value are not Object or Arrays.
Parameters
Name | Description |
---|---|
value |
The value that is going to be mask |
selector |
The PathElement selector |
Example
This example shows how to mask
Source
1
2
3
4
5
6
%dw 2.0
output application/json
import * from dw::util::Values
ns ns0 http://acme.com/foo
---
[{name: "Peter Parker", password: "spiderman"}, {name: "Bruce Wayne", password: "batman"}] mask field("password") with "*****"
Output
1
2
3
4
5
6
7
8
9
10
[
{
"name": "Peter Parker",
"password": "*****"
},
{
"name": "Bruce Wayne",
"password": "*****"
}
]
mask(Any, String): Any
This overload of mask allows to select a field by its name.
Parameters
Name | Description |
---|---|
value |
The value that is going to be mask |
fieldName |
The name of the field to mask |
Example
This example shows how to mask
Source
1
2
3
4
5
6
%dw 2.0
output application/json
import * from dw::util::Values
ns ns0 http://acme.com/foo
---
[{name: "Peter Parker", password: "spiderman"}, {name: "Bruce Wayne", password: "batman"}] mask "password" with "*****"
Output
1
2
3
4
5
6
7
8
9
10
[
{
"name": "Peter Parker",
"password": "*****"
},
{
"name": "Bruce Wayne",
"password": "*****"
}
]
mask(Any, Number): Any
This overload of mask allows to select an Array by its index
Parameters
Name | Description |
---|---|
value |
The value to mask |
i |
The index to mask |
Example
This example shows how the mask
behaves all the first elements of all the arrays
Source
1
2
3
4
%dw 2.0
output application/json
---
[[123, true], [456, true]] mask 1 with false
Output
1
2
3
4
5
6
7
8
9
10
[
[
123,
false
],
[
456,
false
]
]
update
update(Object, String): Any
Updates an Object field with the specified value. This function will return a new Object with the value of the specified field changed.
Parameters
Name | Description |
---|---|
objectValue |
The object to be update |
fieldName |
The field name |
Example
This example update the name of the user
Source
1
2
3
4
5
%dw 2.0
import * from dw::util::Values
output application/json
---
{name: "Mariano"} update "name" with "Data Weave"
Output
1
2
3
4
{
"name": "Data Weave"
}
update(Object, PathElement): Any
Updates an Object field with the specified value. This function will return a new Object with the value of the specified field changed.
Parameters
Name | Description |
---|---|
objectValue |
The object to be update |
fieldName |
The field name |
Example
This example update the name of the user
Source
1
2
3
4
5
%dw 2.0
import * from dw::util::Values
output application/json
---
{name: "Mariano"} update field("name") with "Data Weave"
Output
1
2
3
4
{
"name": "Data Weave"
}
update(Array, Number): Any
Updates an Array index with the specified value. This function will return a new Array with the value of the specified index changed.
Parameters
Name | Description |
---|---|
objectValue |
The Array to be update |
indexToUpdate |
The index of the array to update |
Example
This example update the name of the user
Source
1
2
3
4
5
%dw 2.0
import * from dw::util::Values
output application/json
---
[1,2,3] update 1 with 5
Output
1
2
3
4
5
6
[
1,
5,
3
]
update(Array, String): Any
Updates all Objects inside the specified Array with the given value.
Parameters
Name | Description |
---|---|
objectValue |
The Array of Object to be update |
indexToUpdate |
The field name to update |
Example
This example update the name of the user
Source
1
2
3
4
5
%dw 2.0
import * from dw::util::Values
output application/json
---
[{name: "Mariano"}] update "name" with "Data Weave"
Output
1
2
3
4
[{
"name": "Data Weave"
}]
update(Array, PathElement): Any
Updates an Array index with the specified value. This function will return a new Array with the value of the specified index changed.
Parameters
Name | Description |
---|---|
objectValue |
The Array to be update |
indexToUpdate |
The index of the array to update |
Example
This example update the name of the user
Source
1
2
3
4
5
%dw 2.0
import * from dw::util::Values
output application/json
---
[1,2,3] update index(1) with 5
Output
1
2
3
4
5
6
[
1,
5,
3
]
update(Array | Object | Null, Array<String | Number | PathElement>): Any
Updates the value at the specified path with the given value
Parameters
Name | Description |
---|---|
objectValue |
The value to be update |
path |
The path to update |
Example
This example update the name of the user
Source
1
2
3
4
5
%dw 2.0
import * from dw::util::Values
output application/json
---
{user: {name: "Mariano"}} update ["user", field("name")] with "Data Weave"
Output
1
2
3
4
5
6
{
"user": {
"name": "Data Weave"
}
}
update(Null, Number | String | PathElement): Any
Helper function to make update null friendly.