Invalid Notebook - "The Notebook Does Not Appear to Be Valid JSON" on Github

Hello, all my .ipynb files on Github have this same error message and will not load. I am wondering what I can do to fix this. I recently uninstalled and reinstalled Anaconda and that fixed some bugs for me but it did not fix the Github issue. Thanks in advance to anyone who can help me out.

Just because the preview at Github doesn’t work, doesn’t necessarily mean you won’t be able to open it in Jupyter notebook. If you saved them with older Jupyter notebook, upon trying to open with Jupyter notebook, usually it will get updated by Jupyter notebook to the current standard nbformat.
Also nbviewer is a better static viewer and even allows some javascript so ‘static’ is a little misleading. However, your notebooks may be outdated for even that to handle. I cannot tell because what you shared is an image and not an URL to a notebook, such as https://gist.github.com/fomightez/27b1a1b4820033e1465ec93441362987 which can be viewed in nbviewer like this.

My Jupyter notebook itself works fine, I just want to be able to upload .ipynb files to Github so people can see the output of what I have created vs. just a .py file that has code no one can tell what it does. I am copying and pasting code and adding the file type as .ipynb. Github used to be able to open each file and show the code and the output. Here is a URL to a test file I have, let me know if you see what I see https://github.com/EvanJW7/NBA-Draft-Prospect-Stats/blob/1620575463bebb0a23b9b4d35c7c37adb49a80c8/test.ipynb

What you’ve shared isn’t a notebook despite the extension of .ipynb. Look at the raw view of yours.

Compare that to the raw view of this one, which is nice json (as current notebooks are) and renders in nbviewer well here. The output from that notebook is part of the json and is rendered in the static view.

Yours at https://github.com/EvanJW7/NBA-Draft-Prospect-Stats/blob/1620575463bebb0a23b9b4d35c7c37adb49a80c8/test.ipynb isn’t json. What you’ve shared at there is actually code from in the cells, it seems, from looking at the raw view. If you change the extension of what you linked to .py, you’ll see it is the python code. Which is what you said you said you didn’t want to share. You want the notebook with the output represented.



That isn’t how you do it anymore. And I don’t think Github ever rendered the output if you didn’t provide it.
Now you just save the notebook file directly in .ipynb format and upload it to Github. If you’ve left the output in the cell, it will render some of it in the preview at Github usually. Github has upgraded their handling in the last few years so rendering the preview doesn’t time out as often. However, it isn’t as full-featured as nbviewer and won’t be because that isn’t their intent.



If you host actual notebook files at Github in a repo or gist, you can share them with others using nbviewer to get the nice rendering. It’s just a variation of the URL pattern. They are still hosted at Github and nbviewer points at them. You just supply the nbviewer pattern of the URL to those you want to share them with and they’ll see them with the nice, full-featured rendering.

Interesting, I see what you are saying about the raw view. It used to convert to JSON automatically but not anymore it seems. Why would that be the case? Anyway I will give nbviewer a shot. Thank you for your help!

The format standards of notebooks have changed and perhaps you were using an older standard that Github used to handle better. Gtihub may have deprecated that one when they upgraded how they handle previewing notebooks.

(Is it possible you had Jupytext in your environment and don’t now? That will render notebooks as .py form and keep them in sync.)



The use of nbviewer just requires sharing a different URL as your notebooks would still be on Github. Sometimes it is overkill/somewhat redundant as the Gtihub render has improved much recently. However, you’ll get better results especially with long or wide notebook and those using Plotly and other javascript enhanced rendering.