jupyter / jupyter/notebook

JSON parsing fails too hard

Open
#7,285 1 comment 0 reactions 0 assignees View on GitHub
bug regression
Dominant language
Jupyter Notebook
Stars
13.3k
Forks
5.8k
Avg merge
6d 11h
Merged PRs (30d)
7

Description

## Description

Although the JSON spec does not allow comments, plenty of JSON files have comments in them anyway, e.g.
```
{
"serverlist":
["us-east-1","us-west-1","sea-2"],
//must be a string not an integer
"userid": "13317025461942"
}
```
and plenty of parsers accept (and ignore) these. In Jupyter 6.x, this was fine, and we could edit our .JSON files in Jupyter as a text editor. In Jupyter 7, it seems that the JSON parsing has gotten "smarter". While that's fine and well, it then _refuses to give a basic text editor_.

The user is just met with "JSON.parse: expected property name or '}' at line 2 column 1 of the JSON data" if there's a comment on the second line. And then no editing functionality is available at all, not even just to fix the file. The only option is to rename the file to .txt, edit like that, and then move the file back to .json.

## Reproduce

Create a file named "foo.json" with the body
```
{
//hi
"a":5}
```
and open it in Jupyter. Jupyter gives a parse error and then displays no editor.

## Expected behavior

Jupyter should give a fallback plain-text editor.

## Context

$ jupyter --version
Selected Jupyter core packages...
IPython : 8.18.1
ipykernel : 6.28.0
ipywidgets : not installed
jupyter_client : 8.6.0
jupyter_core : 5.7.1
jupyter_server : 2.12.5
jupyterlab : 4.0.12
nbclient : 0.9.0
nbconvert : 7.16.0
nbformat : 5.9.2
notebook : 7.0.8
qtconsole : not installed
traitlets : 5.14.1

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue by opening foo.json containing the shown comment in Jupyter and confirm that the parse error leaves no editor. Trace the JSON file-opening path that handles this error, then verify that invalid JSON still opens in a plain-text editor while valid JSON behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.