(object-concatenation.dwl)
- Using ++
- Using {( )}
- Using {([ ])}
(string-concatenation.dwl)
- Using ++
- Using $()
(null-checkers.dwl)
- default
- if/else
- (key: value) if condition
%dw 2.0 | |
output application/dw | |
var obj = { | |
FirstName: "Alexandra", | |
LastName: "Martinez" | |
} | |
fun concat(str1, str2) = ( | |
(str1 default "") | |
++ | |
(if (str1 != null and str2 != null) | |
" " | |
else "") | |
++ | |
(str2 default "") | |
) | |
--- | |
{ | |
(obj), | |
Name: obj.FirstName concat obj.LastName, | |
Name1: obj.FirstName concat null, | |
Name2: null concat obj.LastName, | |
(Name3: null concat null) | |
if (concat(null,null) != "") | |
} |
%dw 2.0 | |
output application/json | |
var object1 = { | |
"Key1": "Value1", | |
"Key2": { | |
"Key3": "Value3" | |
} | |
} | |
var object2 = { | |
"Key4": "Value4", | |
"Key5": { | |
"Key6": "Value6" | |
} | |
} | |
--- | |
// Using ++ | |
//object1 ++ object2 | |
//++(object1, object2) | |
// Using {( )} | |
// { | |
// (object1), | |
// (object2) | |
// } | |
// Using {([ ])} | |
{([ | |
object1, | |
object2 | |
])} |
%dw 2.0 | |
output application/dw | |
var str = "World" | |
var obj = { | |
text: "World" | |
} | |
--- | |
{ | |
opt1: "Hello $(str)!", | |
opt2: "Hello $(obj.text)!", | |
opt3: "1+1=$(1+1)", | |
opt4: "Hello " ++ str ++ "!" | |
} |