I want to compare 2 objects and merge them with patch json data. Comparing payload and patch and remove fields from payload if the values are null in patch object.
Input:
{
"firstname":"John",
"lastname":"Sam",
"city": "San Jose",
"path": "additional",
"location-1": {
"address": "USA",
"pin": null
},
"location-2": {
"address": null,
"place": "abc",
"pin": null
}
}
Dataweave Code:
%dw 2.0
output application/json
import mergeWith from dw::core::Objects
var patch = {
lastname:"Courtney",
age:"18",
path: "",
company: "MR",
firstname: null,
city: null,
"location-1": {
"address": "USA",
"pin": null
}
}
---
(payload mergeWith ((patch)) filterObject ($ != null ))
Expected Output:
{
"lastname": "Courtney",
"age": "18",
"path": "",
"company": "MR",
"location-1": {
"address": "USA"
},
"location-2": {
"address": null,
"place": "abc",
"pin": null
}
}
but I am unable to remove null value from location-1 object in the output.