this is my payload
[{
"name": "Zahid"
},
{
"name": "khan"
},
{
"name": "MuleSoft"
}
]
I need to change the key name to user1 user 2 user 3 and so on, so my out should be like
[
{
"user1": "Zahid"
},
{
"user2": "khan"
},
{
"user3": "MuleSoft"
}
]
Note: I am new and learning Dataweave concepts. my friend asked me to join this group and ask any questions for Dataweave. Please help
Anurag Sharma (Nagarro) Forum Ambassador
Hello @Zakir Kh ,
Welcome to the Helper forum. You can solve this question in two ways
answer-1
%dw 2.0
output application/json
---
payload map {
('user'++ $$+1) : $.name
}
answer-1
%dw 2.0
output application/json
---
payload map ((item, index) -> {
('user' ++ (index+1)) : item.name
})
I have used the map function to solve your question, for more knowledge on Map go through this documentation https://docs.mulesoft.com/dataweave/2.4/dw-core-functions-map