Skip to content

Instantly share code, notes, and snippets.

@cftang0827
Created August 30, 2019 05:53
Show Gist options
  • Save cftang0827/cfd62136381dd196a197733ea4ee9860 to your computer and use it in GitHub Desktop.
Save cftang0827/cfd62136381dd196a197733ea4ee9860 to your computer and use it in GitHub Desktop.
The simple script to replace empty value in json to null
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