I am trying to turn a string which should be split on the basis of space and turned into an array of objects. Please help me how can I form it.
Input
field: YYC:16:26 YVR:16:03 YEG:13:43
Output Expected
"details" : [
{
"field" : "YYC",
"time" : "16:26"
},
{
"field" : "YVR",
"Time" : "16:03"
},
{
"field" : "YEG",
"Time" : "13:43"
}
]
A slight twist to what Karthik posted:
%dw 2.0
output application/json
import * from dw::core::Arrays
var test= "YYC:16:26 YVR:16:03 YEG:13:43" splitBy " "
---
details: test map
{
"field": ($ splitBy ":")[0],
"Time": drop(($ splitBy ":"),1)joinBy ":"
}