Ravi Hanok
Ravi Hanok

Reputation: 415

how to get array of integers in dataweave

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)

Upvotes: 0

Views: 9355

Answers (2)

Avi
Avi

Reputation: 11


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]

Upvotes: 1

AnupamBhusari
AnupamBhusari

Reputation: 2415

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

Upvotes: 2

Related Questions