0
votes

I have input values as { {Id:"1"}, {Id:"2"}, {Id:"3"} }

I want output as array {1,2,3} in integer formats using DataWeave in mule anypoint studio so that I can use payload for querying records from sql server database instead looping using for each processor .

I want to use it as

select * from tblQuotes where id in #[payload]

update: It is required like

       select * from tblQuotes where id in (1,2,3)
2

2 Answers

2
votes

Try following

%dw 1.0
%output application/json
---
(payload map {
    id : $.Id as :number
}).*id

For input as

[{"Id":"1"}, {"Id":"2"}, {"Id":"3"}]

Output

[1,2,3]

Hope this helps

1
votes

output: [{"Id":"1"}, {"Id":"2"}, {"Id":"3"}] map ((value , index) -> value.Id as :number)

OR

output: payload map ((value , index) -> value.Id as :number)
For input: 
[{"Id":"1"}, {"Id":"2"}, {"Id":"3"}]
Output: 
[1,2,3]