1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-09 11:42:16 +00:00

Prevent empty lists in JSON responses

This commit is contained in:
spl0k 2013-06-12 23:01:24 +02:00
parent 349dbe6d68
commit d05e2427d0

View File

@ -74,6 +74,18 @@ class ResponseHelper:
@staticmethod
def responsize_json(ret, error = False, version = "1.8.0"):
def check_lists(d):
for key, value in d.items():
if isinstance(value, dict):
d[key] = check_lists(value)
elif isinstance(value, list):
if len(value) == 0:
del d[key]
else:
d[key] = [ check_lists(item) if isinstance(item, dict) else item for item in value ]
return d
ret = check_lists(ret)
# add headers to response
ret.update({
'status': 'failed' if error else 'ok',