โ11-16-2022 08:13 AM
Hi all,
Iโm having an issue while designing the mapping property with null value for my JSON object. For example I have a Mapper to map $input to $body with the expression like follow:
{โmy_idโ: $input.Id,
โmy_nameโ: $input.Name,
โmy_addressโ: $input.Address
}.
When the $input is {โIdโ: 123,โNameโ: null, โAddressโ: โA Street, B District, C Cityโ}, the $body should be: {โmy_idโ: 123,
โmy_nameโ: null,
โmy_addressโ: โA Street, B District, C Cityโ
}. But when the $input is {โIdโ: 123, โAddressโ: โA Street, B District, C Cityโ}, the $body should be:
{โmy_idโ: $input.Id,
โmy_addressโ: $input.Address
}. I tried with hasOwnProperty() and hasPath(), but they all treats the null value as not existing property, so it will not work.
Does anyone know how can I keep the null value for mapping, but eliminate property that does not exist in the $input. Thank you in advanced.
best regards.
โ11-16-2022 09:43 AM
Hi @nluu,
You can try the following expression:
$input.mapKeys((v,k)=> "my_"+k.toLowerCase())
I believe it should do the work.
Regards,
Bojan
โ11-16-2022 11:41 PM
Hi @bojanvelevski,
thank you for your response. It actually a very good solution. But in my case, the name is not always in the format of โmy_โ + key. The name will depends on the naming I agreed with the Database team and the CRM team, so sometime it will be like โclose_dateโ: $input.ProductEffectiveDate_c etc. But Iโll try to base on your suggestion to find out the solution. Thank you so much
Regards
โ12-12-2022 07:34 PM
Hope this helps ๐
{โmy_idโ: โIdโ, โmy_nameโ: โNameโ, โmy_addressโ: โAddressโ }.mapValues((val,key)=> $input.get(val,{})).filter((val,key)=> (!(val instanceof Object)||!(val.isEmpty())))