1
votes

I am trying to split input values using Regex. My input will be like this

"salesforce.com/jobs/2020/06-2020"

the expression am using is below

%dw 2.0
output application/json
---
"FName": vars.Folderstruct splitBy(/[\/]/)

Output:

{
  "FName": [
    "salesforce.com",
    "jobs",
    "2020",
    "06-2020"
  ]
}

But i need my output like this

{
    "FName":"salesforce.com"
},
{
    "FName":"jobs"
},
{
    "FName":"2020"
},
{
    "FName":"06-2020"
}

How can i achieve this through transform?

1

1 Answers

1
votes

Once you have the list with values, what you need is to create a new object with each one, and for that, you can use the map function like this:

%dw 2.0
output application/json
---
vars.Folderstruct splitBy(/[\/]/) map ((item, index) -> 
  {
    FName: item
  }
)