notebook icon indicating copy to clipboard operation
notebook copied to clipboard

JSON parsing fails too hard

Open Timeroot opened this issue 11 months ago • 1 comments

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

Timeroot avatar Mar 01 '24 15:03 Timeroot

@Timeroot, there is already an option to open the JSON files with text editor.

image

itsmevichu avatar Mar 06 '24 17:03 itsmevichu