NotJSONError preventing notebook from being loaded

Hi,

I’m teaching a course and one of my students has run into a NotJSONError(‘Notebook does not appear to be JSON: u’{\n “cells”: [\n {\n “cell_type”: "…’,). The notebook in question is SIR_model.ipynb. I came across a StackOverFlow thread which pointed me to checking the notebook’s JSON validity using a JSON validator. The validator says there’s an error near the end of the file (at position 16996). However, looking through the file with a text editor, I couldn’t see any issues with the JSON format: no unnecessary commas, open-ended quotes or brackets or braces, etc. I then preceded to check a bunch of notebooks I’ve created. None of them are considered valid JSON by this validator. Finally, I created an empty notebook, and it too was invalid JSON. The empty notebook is

{
 "cells": [],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 5
}

I don’t see why there should be any problem with this. If I copy and paste the text from any of the notebooks into the validator, it says it’s valid. But when uploading the file, it says it isn’t. For what it’s worth, I’m using JupyterLab 3.1.7 to create these notebooks.

I’ve suggested they try restarting JupyterLab. Is there any other solution to this?

Thanks,
Zach

The validator says there’s an error near the end of the file (at position 16996).

I copied and pasted the raw content of the notebook in question into the validator and it did not detect any issue. The notebooks also renders fine on GitHub and passes parsing by Python’s json module. It looks like the problem is with how the online JSON validator that you chose reads files - possibly it fails to recognise Unix newlines (\n) and expects Windows newlines (\r\n) instead. Other validators I tried confirm that your notebook is valid.

Maybe your student had an error when downloading the file and it was prematurely truncated?

1 Like

Another check of much of the jupyter stack (beyond github’s renderer) is nbviewer, which looks fine.

Perhaps, if students aren’t git-savy, recommend downloading the repo as a zip file, e.g.

https://github.com/StatPhysBio/biophysics/archive/refs/heads/main.zip

This will ensure they have any supporting files as well.

1 Like

Thanks for resolving that discrepancy and for the tips!