Remove object from body, when all parameter fields are empty

I have the below code

the 4 fields in the compensation_record object are not required. I want to check if all the fields are empty (or null), to remove the compensation_record object entirely from the body, before making the call. How to do that?