How to do mapping as arraylist of maps for below using dataweave mule

1.2k views Asked by At

How to do mapping for below data.

ParameterMap{[card=[15242424211], phone=[54545454545]]}

This data is dynamic which is coming from http request as part queryparameters. I want to form query params in the form #[{'p1':'v1', 'p2':'v2'}] dynamically

for example into [{'card': '15242424211','phone':'54545454545'}]

i.e Array of maps(application/java) Using Dataweave in mule can you please help on this

1

There are 1 answers

5
AnupamBhusari On

use following code

%dw 1.0
%output application/json
---
inboundProperties."http.query.params" mapObject {
    ($$) : $[0]
}

With this output will be {"card": "15242424211","phone":"54545454545"} you can wrap it under array if required by using

%dw 1.0
%output application/json
---
[inboundProperties."http.query.params" mapObject {
    ($$) : $[0]
}]

This will produce output as [{"card": "15242424211","phone":"54545454545"}] Please refer org.mule.module.http.internal.ParameterMap for details of HTTP params.

Hope this help.

Update:- Please use following for setting query parameters for HTTP outbound request.

<dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
inboundProperties."http.query.params" mapObject {
    ($$) : $[0]
}
]]></dw:set-payload>
        </dw:transform-message>