37

Getting this very strange error when I am trying to load my ipython notebook. Never had it before, and I cannot to my recollection, remember having done anything silly with ipython:

Unreadable Notebook: /path/to/notebooks/results.ipynb NotJSONError('Notebook does not appear to be JSON: u\'{\\n "cells": [\\n  {\\n   "cell_type": "...',)

which is followed by

400 GET /api/contents/results.ipynb?type=notebook&_=1440010858974 (127.0.0.1) 36.17ms referer=http://localhost:8888/notebooks/results.ipynb
1
  • For me the issue was actually a python comment. But like @crypdick suggests, using an online JSON validator will show you where the issue is very quickly.
    – jtb
    Sep 23, 2021 at 14:34

18 Answers 18

26

Save yourself a headache. Open your .ipynb in any online JSON validator and it will tell you which lines have issues. I used this one.

2
  • Hi i got this error with an empty file that i created by running vim xxx, so i don't have anything to validate... Does it mean the empty notebook also needs something like a JSON-format?
    – wawawa
    Oct 27, 2022 at 10:08
  • 1
    @wawawa you need to init the ipynb file using jupyter
    – crypdick
    Oct 30, 2022 at 12:08
18

In my case, I am using GitHub to save and share my ipython files with my teammate. When there is a conflict in the code, I had to delete those lines indicating the changes in the conflicting code such as:

>>>>>>>>head
=============

and It works for me.

4
  • I think I have the same problem, but I couldn't see the line in Atom. Which IDE did you use to see the line?
    – Cloud Cho
    Aug 25, 2020 at 7:08
  • 1
    same thing happened, could you elaborate a bit more? Oct 28, 2021 at 4:36
  • This will only happen if there is a merge conflict and you did not resolve the merge. Just do a global search for >>>>> and you will find the conflicts. You can resolve them by keeping only the needed parts and removing the rest including these special keywords. Things will then be resolved, hopefully. Oct 28, 2021 at 11:51
  • As @crypdick 's comment, use the online JSON validator to see where are the conflicts, and then edit them out in any text editor/IDE. Feb 1, 2022 at 13:11
14

This happened to me as well. I opened my data.ipynb file using notepad and found out it was blank.

I managed to recover my file by going into the hidden ipynb_checkpoints folder and copying data_checkpoint.ipynb out into my working directory.

In my Mac OS terminal

cd .ipynb_checkpoints
cp data-checkpoint.ipynb \..

Thankfully the codes were preserved. Hope this helps!

10

I just had the same issue after upgrading from IPython 0.13 (ish) to Jupyter 4.

The problem in my case were a few rogue trailing commas in the JSON, for example the comma following "outputs" in:

...
 "language": "python",
 "metadata": {},
 "outputs": [],
},

After removing the commas, Jupyter/IPython could again read the notebook (and upgraded it to version 4). I hope this helps.

3
  • Hi, only comma after each dictionary?
    – haneulkim
    Apr 26, 2019 at 1:11
  • 3
    An easy way to check errors in json structure is open the jupyter notebook in vs code and click in "Accept changes" for all highlighted errors. Save and then open the nb again as usual
    – Lucas
    Oct 23, 2020 at 18:17
  • The comment of @Lucas avoids using another cookies website :). Someone has also added an answer with this. Sep 6, 2021 at 17:38
6

The easiest way to recover corrupted Jupyter notebook files, whether it contains text or not (size = 0KB), is to go to the project folder and display the hidden files. Once the hidden files are displayed, you will see a folder named '.ipynb_checkpoints'. Simply open this folder and take the file you want!

5

Visual studio code procedure

This is my procedure that usually avoids me groping in the dark.

  1. I installed a json parser validator like this one.
  2. Open the file and save a copy as .json file.
  3. Open the json and look for the errors.
  4. Save it back to the .ipynb extension.

Usually, I manage to fix the errors quickly.

5

Jupyter autosaves in a specific way. It means You have accidentally closed the notebook before properly saving it.

You need to look for three things -

  • Search for <<<<<<< and delete those lines.
  • Search for ====== and replace those lines with ,.
  • Search for >>>>>>> and delete those lines.

It will work fine after this.

3

this can be changed to reformat your ipynb file to readable in jupyter notebook. check your other ipynb files(open in notepad) which are working fine with your jupyter notebook, check and compare at the end of the files in notepad. there you can reformat the file which is not working.

2

I had this issue from accidentally saving as .txt from github and solved by deleting .txt (leaving .ipynb instead of .ipynb.txt when downloading)

2

Yes, the best solution for me was I saved my notebook in HTML format, then opened it in Notepad ++ , delete the long repeated lines of output which were causing my notebook to grow to 45MB, once that cleared, Saved the file back into (.ipynb) format , and was able to opened it with no JSON error. Hope that worked for others as well!

0

Got this error after conflicts while pushing my code to Github. The code present on the repo was old, and my changes were stashed. Notebook wasn't opening in either Jupyter and github repo. Following above comments, I searched for the part in my code which was giving JSON error,i.e. '<<<<<<<<<<<', '=======' and '>>>>>>>>>>' characters using an online json parser. Then I opened my .ipynb notebook in notepad++ and manually replaced these characters with blank string ''. After this, the notebook opened on my local Jupyter, and I also pushed the changes to Github.

0

I have changed by ipynb file encoding from UTF-8-BOM to UTF-8, and then it worked.

0

My native language is not English, but because this problem helped me a part, I came to feedback my solution. The following is translated with translation software: Fundamentally, the file format is messed up due to wrong closing. When opening, the correctness of the json format will be checked first, and an error will be returned if it is found to be wrong. The mess in my file format is not <<<<< or ====== but the lack of commas. Either way, it's best to use a piece of software to detect errors in the json syntax, and then manually fix it yourself. The json website detection provided by the highest praise is available, but the detection errors are not complete, and may need to be detected-modified-detected-modified. Also use vscode to open the file, vscode will prompt the location of the json syntax error, which is also incomplete and needs to be checked and modified multiple times.

The error location provided is more difficult to find. I use nodepad++, and the lower right corner can display how many characters are selected (standard, including line breaks). Then select from the first character until the destination position. Although it's a bit stupid, the main reason is that I didn't find the relevant positioning method.

0

Clear all outputs. Then copy the notebook.

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Sep 6, 2022 at 19:37
0

If you use Jupyter-Notebook in VS code, just save it in VS code, close the file and try to open it again by accessing the browser.

0

on ubuntu 20.04, I have file String.ipynb. I had same problem because I coded ơ [ echo 'hello' >> String.ipynb ]. deleting 'hello' in String.ipynb -> I could open my notebook like normal. how did I delete? [ nano String.ipynb ] * move to last line (hello) * -> delete it. I hope my answer help you :D

0

you will see this error may be because, you were getting merge conflict in .ipynb file. because of that git adds >>>>>>>> HEAD thing in .ipynb file which makes is unreadable.

To overcome this issue open .ipynb file in vim editor and then remove the incoming changes or your changes as per your use case.

vim <your-.ipynb-file-path>

To remove incoming changes remove content between these lines<<<<<<<<<< HEAD ==============. Note:- remove this line as well >>>>>>>>>>>> this line.

to remove your changes remove content between these lines ============== >>>>>>>>>>>. Note:- remove this line as well a <<<<<<<<<< HEAD

-2

I had the same issue after git merge while using VS Code and Jupyter extension.

VS Code would not open the notebook after the merge conflicts were highlighted in the notebook JSON by git (e.g. <<<<<). One way around it was to highlight the changes and accept one by one using the file viewer in the VSCode git interface.

Alternative that worked for me was to rename the file to .json so that it would open and then search for each instance of <<<<< and accept the incoming change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.