Skip to content

Instantly share code, notes, and snippets.

@asimjalis
Last active February 9, 2020 22:41
Show Gist options
  • Save asimjalis/26e0c36462cbfe0f6061cef306f6e8da to your computer and use it in GitHub Desktop.
Save asimjalis/26e0c36462cbfe0f6061cef306f6e8da to your computer and use it in GitHub Desktop.
Print Python Objects as JSON
import json
def dbg(obj,msg=""):
"Print nested data structures recursively for debugging."
def get_serializable(obj):
if hasattr(obj,"__dict__"):
return obj.__dict__
else:
return obj
print(msg, json.dumps(obj, default=get_serializable, sort_keys=True, indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment