---
title: "Convert Empty String in a JSON to a \"null\" value"
date: 2025-12-30T05:31:06Z
modified: 2026-06-12T08:57:28Z
permalink: "https://ezintegrations.ai/docs/replace-empty-strings-with-null/"
type: docs
status: publish
excerpt: ""
wpid: 3065
doc_category:
  - Pycode Examples
author: Arun Thakur
---

## 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.

1. Open the Python Code Operation in eZintegrations.
2. Paste the provided script into the PyCode editor.
3. Ensure the incoming dataset is stored in **pycode\_data**.
4. Save and deploy the workflow.
5. 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

 ### 1. What does None represent in JSON?

 In Python, None is converted to null when serialized into JSON format.

 

 

  ### 2. Does this script handle nested JSON objects?

 No. This script processes only top-level keys. Nested objects require recursive logic.

 

 

  ### 3. Will numeric or boolean values be affected?

 No. Only values equal to an empty string are converted.

 

 

  ### 4. Is this conversion mandatory for all integrations?

 No. It is required only when downstream systems expect null instead of empty strings.

 

 

  ### 5. 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.

## Topics

**Docs Categories:** [Pycode Examples](https://ezintegrations.ai/wp-content/uploads/wp-mfa-exports/taxonomy/doc_category/pycode-examples.md)