In the backend django I will return data to frond end as json, but in frondend there are many "null" value, and one solution is to change code to convert value None to empty string "" when create the value, but since there are many places, I'd like to write a customized encoding function to convert None to "" when dump the obj into string. I used the following class, but it doesn't work:
class PythonObjectEncoder(json.JSONEncoder):
def encode(self, obj):
if obj is None:
obj = ''
return json.JSONEncoder().encode(obj)
data = [1,2,3,None,
[[[2],3],4]
]
j = json.dumps(data, cls=PythonObjectEncoder)