Immadisetty Nikhila
Immadisetty Nikhila

Reputation: 11

In mule how will I transform with dynamic parent values

Input:    
{    
"2019-02-17":[    
{    
"date":"2019-02-17",    
 "address":"ap",    
"city":"vijayawada"    
}    
],    
"2019-02-18":[    
{    
"date":"2019-02-18",    
"address":"west bengal",    
"city":"kolkata"    
 },
{    
"date":"2019-02-18",    
"address":"tamil Nadu",    
"city":"chennai"    
 }    
]    
} 

 Output:
 To be transformed to        
{    
"Address":[    
{    
"date":"2019-02-17",    
 "address":"ap"    
 },    
{     
"date":"2019-02-18",    
"address":"west bengal"    
},
{     
"date":"2019-02-18",    
"address":"tamil nadu"    
}
]    
 } 

How do I transform with the help of dynamic parent keys. Trying to transform with the help of mapObject but getting the fields as array of string format

Upvotes: 0

Views: 71

Answers (1)

Manish Yadav
Manish Yadav

Reputation: 310

You can achieve your expected output by using Pluck operator. Please find the below code.

    %dw 2.0
output application/json  
---

  address: (payload pluck $) flatMap $ map (item, index) -> {
    date: item.date,
    address: item.address
  }

Thanks,

Manish Yadav

Upvotes: 2

Related Questions