Skip to content

Instantly share code, notes, and snippets.

@harunyasar
Created December 11, 2015 13:39
Show Gist options
  • Save harunyasar/25db367e2fbf57f55f56 to your computer and use it in GitHub Desktop.
Save harunyasar/25db367e2fbf57f55f56 to your computer and use it in GitHub Desktop.
Convert SUDS response object to dict
from suds.sudsobject import asdict
def recursive_asdict(d):
"""Convert Suds object into serializable format."""
out = {}
for k, v in asdict(d).iteritems():
if hasattr(v, '__keylist__'):
out[k] = recursive_asdict(v)
elif isinstance(v, list):
out[k] = []
for item in v:
if hasattr(item, '__keylist__'):
out[k].append(recursive_asdict(item))
else:
out[k].append(item)
else:
out[k] = v
return out
def suds_to_json(data):
return json.dumps(recursive_asdict(data))
@ffeast
Copy link

ffeast commented Sep 6, 2017

nice,
but what about the reverse operation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment