1
votes

how can i create map variable in dataweave from 2 lists where the first element in first list should be the key in the map and first element from second list should be the value in the map and so on...

Below script is throwing error.

%dw 1.0 %output application/json %var accountIdMap = { (payload.*accountIdList): payload.*accountNameList }

1

1 Answers

1
votes

Assuming the order and number of elements in both lists are same, you should map on one list and then create elements -

%var accountIdMap = (payload.accountIdList map ('$':payload.accountNameList($$)))

$ = current element in iteration from accountIdList $$ = index of current iteration from accountIdList. Get element at same index from other list.