INNER CODE UNIT · Python
replace_values_with_none
bkbilly/lnxlink · lnxlink/__main__.py:358
def replace_values_with_none(self, data):
"""Replaces specified values with None recursively"""
if isinstance(data, bytes):
try:
data = data.decode("utf-8")
except Exception:
data = None
if isinstance(data, str):
try:
parsed = json.loads(data)
if isinstance(parsed, (dict, list)):
return json.dumps(self.replace_values_with_none(parsed))
except (json.JSONDecodeError, TypeError):
pass
return None
if isinstance(data, dict):
return {
key: self.replace_values_with_none(value) for key, value in data.items()