user3165854
user3165854

Reputation: 1655

Split delimited string and store values in JSON object using dataweave

I have a CSV file which sends records in the following format:

John,Smith,presentation|researcher|developer,[email protected],07891234567

I need to take each record and map them to a list of the following JSON object:

[
   {
      "firstName": "John",
      "surname": "Smith",
      "skills": 
      [
         "presentation",
         "developer",
         "researcher"
      ]
      "email": "[email protected]",
      "phone": "07891234567"
   }
[

My problem is that how do you split the address text string and populate the address object along with the other fields using Dataweave and the Transform message component in Mule 3.8.1?

Thanks

Upvotes: 0

Views: 3316

Answers (1)

Chad Gorshing
Chad Gorshing

Reputation: 3118

You can use the splitBy to get what you are wanting.

%dw 1.0
%input payload application/csv
%output application/json
---
payload map {
  firstname: $.firstname,
  lastname: $.lastname,
  skills: $.skills splitBy ('|'),
  email: $.email,
  phone: $.phone
}

Upvotes: 2

Related Questions