In my case, I’m updating a field name that contains NAME or Number then i’m updating that field value as “******”. for example, {"firstName": "John"} is updated as {"firstName": "******"}
using below dataweave code that I tried in below:
%dw 2.0
output application/json
import * from dw::util::Values
import * from dw::core::Types
fun masking(key,val) = if(!isEmpty(val) and (sizeOf(val)>0) and ((key contains "NAME") or (key contains "NUMBER"))) ("******") else val
fun maskMessage(keyname,value) =
if (typeOf(value) as String == "Object")
(value mapObject { ($$) : maskMessage($$,$) })
else if (typeOf(value) as String == "Array")
(value map { ($$) : maskMessage($$,$) })
else if (typeOf(value) as String == "String") masking(upper(keyname as String), value)
else value
---
maskMessage("",payload)
But this code giving problem for other fields adding 0 or 1 as default root node.
Sample Request:
{
"smrSysten": {
"smrDetails": {
"smrName": "DTI01922",
"status": "Active"
},
"ownerDetails": {
"firstName": "John Mike",
"languagePreferences": [
"English",
"Russian"
]
},
"secondOwnerDetails": [
{
"NameProvided": "Will Jack",
"languagePreferences": [
"English",
"Spanish"
]
}
]
}
}
Expected Output:
{
"smrSysten": {
"smrDetails": {
"smrName": "******",
"status": "Active"
},
"ownerDetails": {
"firstName": "******",
"languagePreferences": [
"English",
"Russian"
]
},
"secondOwnerDetails": [
{
"NameProvided": "******",
"languagePreferences": [
"English",
"Spanish"
]
}
]
}
}
where place name field occur then the value of that field should be updated as “******”. other field values should remains same. The request may be an array or object, this name field will comes in under any section. my dataweave code is working but it adding some interger as node.
Expert, please help me solve this logic.
Thanks in advance.