Skip to main content

I have a string like this -- 6567,CO,1000,25,01-APR-2024,31-MAR-2025|55677,RA,1000,25,01-APR-2024,31-MAR-2025 and I want to convert it into an array of json objects like below -

list : [

{ "code": "6567",

"desc": "CO",

"value": 1000,

"rate":25,

"startDate": "01-APR-2024",

"endDate": "31-MAR-2025"

},

{ "code": "55677",

"desc": "RA",

"value": 1000,

"rate":25,

"startDate": "01-APR-2024",

"endDate": "31-MAR-2025"

}

]

 

How to perform this in Dataweave 2.0 ?

3 answers
  1. Apr 22, 2024, 6:38 AM

    Hi @Lakshmipriya Muthukumaran​ 

    Assuming the order of values wont change in the input text, you can use below dw script.

     

    %dw 2.0

    output application/json

    ---

    (payload splitBy ("|")) map (($ splitBy (","))) map {

    "code": $[0],

    "desc": $[1],

    "value": $[2],

    "rate":$[3],

    "startDate": $[4],

    "endDate": $[5]

    }

    Hi @Lakshmipriya Muthukumaran​ Assuming the order of values wont change in the input text, you can use below dw script. %dw 2.