Valid Lambda Expression type -> function
(user) -> {firstName, LastName, email}
User parameter becomes object:
{
"firstName": "Joe",
"lastName":"Smith",
"email":"Joe@abc.com"
}Dataweave {} represents an object
user: {
firstName: payload.fname,
lastName: payload.lname,
address:{
street: payload.street,
townPin: payload.city
}
}
payload
{
"fname": "Joe",
"lname": "Smith",
"street": "Main Street",
"city": "Charlotte"
}
becomes:
{
"firstName": "Joe",
"lastName":"Smith",
"address": {
"street": "Main Street",
"city": "Charlotte"
}
}Input
Joe Tim George junk
Dataweave
names: payload.users.*name
Output
Joe Tim George
@ represents attribute of XML
bob
Dataweave
userId: payload.user.@id;
Output:
234
Map Operators
$ - Single item of map
$$ - 0 based index of current item
Input
9.99
53
398
Transform
priceList: payload.prices map (
'\$\$': {
dollars: $
}
)Output:
{
"priceList": {
[
{
"0":{
"dollars": 9.99
}
},
{
"1":{
"dollars": 53
}
}
{
"2":{
"dollars": 398
}
}
]
}
}Map Operators
$ - Single item of map
$$ - 0 based index of current item
Input
9.99
53
398
Transform
priceList: payload.prices map (
'\$\$': {
dollars: $
}
)Output:
{
"priceList": {
[
{
"0":{
"dollars": 9.99
}
},
{
"1":{
"dollars": 53
}
}
{
"2":{
"dollars": 398
}
}
]
}
}XML Trick 1
Output must resolve to single root object
{
fname: "John",
lname: "Smith"
}
fails no root objectname: {
fname: “John”,
lname: “Smith”
}
works
XML Trick 1
Output must resolve to single root object
{
fname: "John",
lname: "Smith"
}
fails no root objectname: {
fname: “John”,
lname: “Smith”
}
works
Note on * multiselector
An expression can have multiple * such as
payload.music.artists.artist.discography.albums
will all albums.