Skip to main content

Hi All,

 

My request is

 

{

 "data": {

  "response": {

   "product": {

    "id": "ST22"

   },

   "coverageResponse": [

    {

     "selected": true

    },

    {

     "selected": false

    }

   ]

  }

 }

}

 

as a reponse I want "response" tag to be removed and "product" to be replaced by "inventory"

 

{

 "data": {

   "inventory": {

    "id": "ST22"

   },

   "coverageResponse": [

    {

     "selected": true

    },

    {

     "selected": false

    }

   ]

  }

 }

 

I have done it like below

{

"data":

"inventory": payload.data.response.product,

"coverageResponse": payload.data.response.coverageResponse

}

 

But this is bringing coverageResponse in the same level as data.

4 answers
  1. Aug 13, 2021, 7:07 AM

    @Tulasi qkcoAPuJV​ 

     

    Try this out:

     

    %dw 2.0

    import * from dw::util::Values

    output application/json

    ---

    (payload update {

    case .data -> $[0]

    }) update {

    case .data -> ($) mapObject() -> {

     

    (if(($$) as String == "product") "inventory": ($) else ($$): ($))

    }

    }

     

    Output:

    @Tulasi qkcoAPuJV​ Try this out: %dw 2.0import * from dw::util::Valuesoutput application/json---(payload update {case .data -> $[0]}) update {case . 

    -Sufi

0/9000