• Instructions to Ask a Question

    Click on the "Ask a Question" button and select the application for which you would like to ask questions.

    We have 5 different products namely - Pabbly Connect, Pabbly Subscription Billing, Pabbly Email Marketing, Pabbly Form Builder, Pabbly Email Verification.

    The turnaround time is 24 hrs (Business Hours - 10.00 AM to 6.00 PM IST, Except Saturday and Sunday). So your kind patience will be highly appreciated!

    🚀🚀Exclusive Discount Offer

    Just in case you're looking for any ongoing offers on Pabbly, you can check the one-time offers listed below. You just need to pay once and use the application forever -
     

    🔥 Pabbly Connect One Time Plan for $249 (🏆Lifetime Access) -  View offer 

    🔥 Pabbly Subscription Billing One Time Plan for $249 (🏆Lifetime Access) - View offer

Stripping out empty properties from JSON requests

apps

Member
Hi,
I am working with an API (onparallel.com) that has some issues where it submits replies into fields that are empty instead of just ignoring empty properties in the request which causes big issues.

See the example below:
All properties that are empty should be removed from the request - eg. the property office_address_entity and office address 4' (which areempty) should be removed from the request completely.

EXAMPLE
From this:

{
"name":"John Doe",
"age": 30,
"email": "",
"address": null,
"phone": "123-456-789"
}

so the result is this:
{
"name":"John Doe",
"age": 30,
"phone": "123-456-789"
}

And there can be many of such properties that are empty. And there are up to 200 properties that might or might not be empty so using a manual search and replace action is not an option.
I tried using the regex replace text formatter here and have issues:
1728487299337.png
 

ArshilAhmad

Moderator
Staff member
Hi @apps,

Please try using this Python code to see if it gives you the desired result.
Python:
def remove_empty_properties(data):
    """
    Recursively remove empty properties (None or empty string) from a dictionary.
    
    Args:
        data (dict): The input dictionary to clean.
        
    Returns:
        dict: A new dictionary with empty properties removed.
    """
    # Create a new dictionary with non-empty values
    return {key: value for key, value in data.items() if value not in ("", None)}

# Example input
request_data = {
    "name": "John Doe",
    "age": 30,
    "email": "",
    "address": None,
    "phone": "123-456-789"
}

# Remove empty properties
cleaned_data = remove_empty_properties(request_data)

print(cleaned_data)

 

apps

Member
Thanks ArshilAhmad. I got your code to work :) The only issue is that "None" is not text I need to remove. I need to remove "null" but Null can't be removed it seems (even if I replace None with null in the script it errors).

But I don't need that part working for now. So this is great for now! 🙏
 
Top