Skip to content

Instantly share code, notes, and snippets.

@jmmshn
Last active October 13, 2021 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmmshn/d37d5a1be80a6da11f901675f195ca22 to your computer and use it in GitHub Desktop.
Save jmmshn/d37d5a1be80a6da11f901675f195ca22 to your computer and use it in GitHub Desktop.
[display_JSON] cleanup and display a JSON file
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