Skip to content

Instantly share code, notes, and snippets.

%dw 2.0
import * from dw::util::Values
import * from dw::core::Strings
output application/json
fun lastNameMask(lastName) = lastName[0] ++ "***"
fun phoneMask(x) = "(###)-###-" ++ x[-4 to -1]
fun emailMask(email) = "***@" ++ substringAfterLast(email, "@")
type Currency = String{format: "\$#,###.00"}
var payload = {
"employees": [{
%dw 2.0
output application/json
var payload = [{
"id": "111",
"name": "Ernie",
"address": "Hulo"
}, {
"id": "112",
"name": "John",
"address": "Huawei",
@ravitejagrt
ravitejagrt / ParseNestedJSONwithDynamicKeys.dwl
Last active January 1, 2021 20:20
Parse Nested JSON with Dynamic Keys
%dw 2.0
output application/json
import * from dw::core::Strings
var payload = {
"data": {
"schema": "g5uhJxM3EDHB9UQ5rdqfhw",
"payload": {
"BillingAddress": {
"State": "MN",
"Street": "45 WEST 132ND RD",
%dw 2.0
import * from dw::core::Strings
output application/json
var request = {
"message": "((drawingName1)){{v1}}||((drawingName2)){{v2}}||((drawingName3)){{v3}}|"
}
var p = request.message splitBy '||'
fun getStringBeforeAfter(str, after, before) = substringAfter(substringBefore(str,before), after)
---
%dw 2.0
import divideBy from dw::core::Objects
output application/json
var payload = [
{ "id":"1", "q1":"ans1", "q2":"ans2" },
{ "id":"1", "q1":"ans11", "q2":"ans22", "q3":"ans33", "q4": "ans44" }
]
var resp = [
{ "id":"1", "questionNum":"q1", "answer":"ans1" },
%dw 2.0
import * from dw::core::Arrays
input payload application/csv header=false
output application/json
var GroupRecordHeaders = payload filter ($.column_0 == "03")
var GroupRecordHeaderIndices = GroupRecordHeaders map (indexOf(payload, $))
var GroupRecordTrailers = payload filter ($.column_0 == "49")
var GroupRecordTrailersIndices = GroupRecordTrailers map (indexOf(payload, $))
%dw 2.0
output application/json
var payload = [{
a: " multi "
},
{
a: " rty "
}]
@ravitejagrt
ravitejagrt / convertUSAphonenumber
Last active October 12, 2020 04:33
Convert usa phone number in dataweave 2.0 in Mule 4
%dw 2.0
import java!org::apache::commons::lang3::StringUtils
output application/json
fun getNum(x)= (x replace /[- +()]/ with(""))
var payload = "+19876543210"
---
{
value: StringUtils::substring(getNum(payload), 1, sizeOf(getNum(payload)))
}
@ravitejagrt
ravitejagrt / datatoxml.dwl
Created October 9, 2020 19:46
Convert data to XML with multipel namespaces in root element in dataweave 2.0 Mule 4
%dw 2.0
output application/xml
var attributes = {
"queryParams": {
"countryID": "AV",
"regionID": "AV"
}
}
ns ws http://wwww.informatica.com/loc/ws
@ravitejagrt
ravitejagrt / arraytostring.dwl
Created October 9, 2020 19:25
Dataweave code to convert contents of array to a string using Dataweave 2.0 in Mule 4
%dw 2.0
import * from dw::core::Strings
output application/json
var payload = [{
"id": 1,
"name": "Book",
"quantity": 100
},
{
"id": 2,