Skip to content

Instantly share code, notes, and snippets.

@emoran
Created February 10, 2022 14:33
Show Gist options
  • Save emoran/e2f536c5bf8d50c2ba98a5a0c8bc4690 to your computer and use it in GitHub Desktop.
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
%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