Created
August 30, 2019 05:53
-
-
Save cftang0827/cfd62136381dd196a197733ea4ee9860 to your computer and use it in GitHub Desktop.
The simple script to replace empty value in json to null
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remove_empty_string(dic): | |
""" | |
Replace empty string to None | |
""" | |
for e in dic: | |
if isinstance(dic[e], dict): | |
dic[e] = remove_empty_string(dic[e]) | |
if (isinstance(dic[e], str) and dic[e] == ""): | |
dic[e] = None | |
if isinstance(dic[e], list): | |
for entry in dic[e]: | |
remove_empty_string(entry) | |
return dic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment