Skip to main content

Input payload :

{

"line_items":

[

{

"id": "12344",

"unit_amount": 5999,

" billing_period": 1,

"billing_period_unit": "year"

},

{

"id": "8907",

"unit_amount": 676879,

" billing_period": 1,

"billing_period_unit": "year"

}

]

}

 

Output payload:

{

"line_items":

[

{

"id": "12344",

"unit_amount": 59.99,

"billing_period": 1,

"billing_period_unit": "year"

},

{

"id": "8907",

"unit_amount": 6768.79,

"billing_period": 1,

"billing_period_unit": "year"

}

]

}

 

I don't want to have one-one mapping, is there a way to use update function and just have the mapping for unit_amount as i want to have transformation logic only unit_amount i.e unit_amoount/100. Rest of the fields should be mapped as it is.

 

#Mule 4​  #DataWeave 2​ 

3 Antworten
  1. 9. Aug. 2023, 10:29

    %dw 2.0

    output application/json

    ---

    {

    "line_items": payload.line_items map {

    "id": $.id,

    "unit_amount": $.unit_amount / 100,

    "billing_period": $.billing_period,

    "billing_period_unit": $.billing_period_unit

    }

    }

0/9000