Last active
May 5, 2020 01:24
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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