Last active
October 13, 2021 18:20
-
-
Save jmmshn/d37d5a1be80a6da11f901675f195ca22 to your computer and use it in GitHub Desktop.
[display_JSON] cleanup and display a JSON file
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
from IPython.display import JSON, display | |
from json import JSONEncoder, loads | |
class MyEncoder(JSONEncoder): | |
def default(self, o): | |
try: | |
return o.as_dict() | |
except: | |
try: | |
return o.__dict__ | |
except: | |
return str(o) | |
show_json = lambda x : display(JSON(loads(MyEncoder().encode(x)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment