Skip to main content

#Transformation0 discutindo

Input json:

[

{

"SR#": "1",

"PropertyName": "shipToaddres",

"YES": "success",

"NO": "fail",

"NA": "fail"

},

{

"SR#": "2",

"PropertyName": "billToadress",

"YES": "fail",

"NO": "fail",

"NA": "success"

}

]

 

required output:

{

"shipToaddres": "success",

"billToadress": "success"

}

 

dwl:

%dw 2.0

output application/json

var a = {

    "shipToaddres": "YES",

    "billToadress": "NA"

}

 

fun mapper(k,b) = payload map ((item, index) -> if(item.PropertyName ~= k ) item.b else "") joinBy ""

 

---

a mapObject ((value, key, index) ->(key): mapper((key),value) )

 

II dont understand why item.b resolves to null

 

#DataWeave 2​ #Mule 4​ #transformation

2 respostas
  1. 3 de jul. de 2023, 06:48

    In case of more than two objects in payload, you can do it in below way as well if it is relevant to your use case.

     

    %dw 2.0

    output application/json

    var a = {

    "shipToaddres": "YES",

    "billToadress": "NA"

    }

     

    var payloadMapper = {(payload map(

    ($.PropertyName) : $

    ))}

    ---

    payloadMapper mapObject ((value, key, index) ->{

    (key): value[a[key]]

    } )

     

    In case of more than two objects in payload, you can do it in below way as well if it is relevant to your use case. %dw 2.

0/9000