Created
February 10, 2022 14:33
-
-
Save emoran/e2f536c5bf8d50c2ba98a5a0c8bc4690 to your computer and use it in GitHub Desktop.
Dataweave 2.0 Script that allows to set dynamically fields from a payload and set the date format for strings that are date / datetime
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 | |
import try, fail from dw::Runtime | |
output application/java | |
fun isDate(value: Any): Boolean = try(() -> value as Date).success | |
fun getDate(value: Any): Date | Null | Any = ( if ( isDate(value) ) value | |
as Date as String else value ) | |
--- | |
(payload map (item,index) ->{ | |
(item mapObject ((value, key, index) -> { | |
(key):(getDate(value)) | |
} )) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment