How to remove fields/ keys with null values in a dataset

Illustrated below is an example of a flow where the Record Generator is the source step.

The below page is the dataset which contains fields that have null values.

image

To remove the fields that have null values in the dataset, the code in the image below is used in a Calculator step.

image

Copy and paste the below code in the Calculator step:

let inputRecord=input.record;
for(const key in inputRecord){
    if (!inputRecord.hasOwnProperty(key)) continue;
        if(!inputRecord[key]){
            delete inputRecord[key];
        }
}
return inputRecord;

Illustrated below is the output results after the above code is added in the Calculator step.

image