8

Jupyter Notebook (and Jupyter Lab) comes with a very convenient and interactive JSON formatter. It's very useful for letting a user look through a very deep dictionary without flooding the output cell with a huge amount of information. Normally, if we have a dictionary called my_dict, you can print its contents neatly to the output cell by:

from IPython.display import display, JSON
display(JSON(my_dict))

Which will give you something that looks like this: enter image description here

The user can then interact with it to open/close different portions.

The problem is that if you take this approach, it doesn't seem to render properly on GitHub's web browser. In its place, you'll get:

<IPython.core.display.JSON object>

Any way I could have a nice JSON viewer like this that works on both a local JupyterLab instance, and on GitHub's website? Or am I forced to flood the output cell with hundreds of lines of JSON?

krassowski
  • 13,598
  • 4
  • 60
  • 92
AmphotericLewisAcid
  • 1,824
  • 9
  • 26
  • 2
    The nice rendering is enabled by https://www.npmjs.com/package/@jupyterlab/json-extension. GitHub uses (possibly an outdated version of) nbviewer to render notebooks. Does it work in nbviewer? If yes, then you should probably request this as a feature from GitHub. They recently said they are working on improving the notebooks integration. – krassowski Jan 29 '21 at 04:09
  • Never used nbviewer before, but it's worth a test. Where does GitHub track their feature requests? Thanks btw! – AmphotericLewisAcid Jan 29 '21 at 19:50
  • https://support.github.com/contact/feedback and https://github.community/ – krassowski Jan 29 '21 at 19:54

0 Answers0