Skip to main content

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

답변 6개
  1. Anurag Sharma (Nagarro) Forum Ambassador
    2022년 5월 2일 오전 5:33

    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

0/9000