Skip to content

Instantly share code, notes, and snippets.

@djuang1
Last active May 5, 2020 01:24
Show Gist options
  • Save djuang1/4ee0d2a8699f6fa7da0216dbca809f6b to your computer and use it in GitHub Desktop.
Save djuang1/4ee0d2a8699f6fa7da0216dbca809f6b to your computer and use it in GitHub Desktop.
MuleSoft DataWeave 2.0 script example that shows replace a single value in a payload without having to map every field.
%dw 2.0
output application/json
---
payload mapObject (value, key) -> {
// key to compare needs to be set to String type
(if (key as String =="provisioned") {
// if key = "provisioned", change the value to true
"provisioned": true
} else if (key as String =="key1"){
// leaving this blank will remove the element
} else {
// otherwise output the key/value pair
(key): (value)
})
}
// Example payload
//{
// "key1": "1"
// "provisioned": false
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment