Overview
Converting empty string values to null in a JSON dataset is a common data normalization requirement in integration workflows.
In eZintegrations, Python Operations can be used to automatically replace all empty string values with null across the entire JSON record.
When to Use
Use this method when empty strings need to be standardized as null values for improved data consistency and compatibility.
- Preparing data for APIs that require null instead of empty strings
- Improving database compatibility
- Standardizing missing value representation
- Cleaning incoming JSON datasets
- Ensuring consistent schema validation
How It Works
The Python script iterates through all key-value pairs in the JSON object.
If a value equals an empty string (""), it is replaced with None, which converts to null in JSON format.
Python Operation Code
Use the following script in the PyCode editor inside Python Code Operations.
Responsedata = []
new_data = pycode_data
converted_json = {
key: None if value == "" else value
for key, value in new_data.items()
}
json_result = json.dumps(converted_json, indent=4)
pycode_data = json_result
Example
Input JSON
{
"name": "John",
"email": "",
"phone": "",
"city": "New York"
}
Output JSON
{
"name": "John",
"email": null,
"phone": null,
"city": "New York"
}
How to Use
Follow these steps to convert empty strings to null values.
- Open the Python Code Operation in eZintegrations.
- Paste the provided script into the PyCode editor.
- Ensure the incoming dataset is stored in pycode_data.
- Save and deploy the workflow.
- Test with sample JSON input containing empty strings.
Troubleshooting
- Ensure the input data is a valid JSON object.
- Verify that json module is available in the execution environment.
- Check for nested objects if empty strings are not converted.
- Confirm that pycode_data contains a dictionary, not a string.
- Review logs if null values do not appear in output.
Frequently Asked Questions
What does None represent in JSON?
In Python, None is converted to null when serialized into JSON format.
Does this script handle nested JSON objects?
No. This script processes only top-level keys. Nested objects require recursive logic.
Will numeric or boolean values be affected?
No. Only values equal to an empty string are converted.
Is this conversion mandatory for all integrations?
No. It is required only when downstream systems expect null instead of empty strings.
Can I modify this to process arrays?
Yes. The script can be extended to iterate through lists and nested structures.
Notes
- This script replaces only exact empty string values (“”).
- Test changes before applying to production workflows.
- Consider recursive processing for deeply nested JSON.
- Ensure consistent null handling across systems.