Last active
February 9, 2020 22:41
-
-
Save asimjalis/26e0c36462cbfe0f6061cef306f6e8da to your computer and use it in GitHub Desktop.
Print Python Objects as JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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