Support newline delimited JSON (NDJSON) with MIME type application/x-ndjson
Categories
(DevTools :: JSON Viewer, enhancement, P3)
Tracking
(Not tracked)
People
(Reporter: asuth, Unassigned)
References
()
Details
https://github.com/ndjson/ndjson-spec covers a pretty common convention of having a file that consists of newline-delimited JSON as indicated by MIME type application/x-ndjson. For example, this is the file format for Searchfox's analysis files. (This is also why I'm making the enhancement request... I'm changing Searchfox to expose these files and it would be cool to be able to use the JSON viewer UI.)
The general idea would be to treat the NDJSON formatted:
{ "line" : 1 }
{ "line" : 2 }
{ "line" : 3 }
like it was:
[{ "line" : 1 },
{ "line" : 2 },
{ "line" : 3 }]
Comment 1•6 years ago
|
||
Thanks for the report!
Agree, it makes sense to support application/x-ndjson
Honza
Comment 2•6 years ago
|
||
Some pointers to the source code for anyone interested in fixing this bug:
-
Here is the place where JSONViewer is checking supported mime type
https://searchfox.org/mozilla-central/rev/6bceafe72cad5d5752667b4b6bd595d3a4047ca3/devtools/client/jsonview/converter-observer.js#72-97 -
Here is where we create text node in the page with JSON data
https://searchfox.org/mozilla-central/rev/6bceafe72cad5d5752667b4b6bd595d3a4047ca3/devtools/client/jsonview/converter-child.js#321 -
As data are coming from the server we are appending them into the text node
https://searchfox.org/mozilla-central/rev/6bceafe72cad5d5752667b4b6bd595d3a4047ca3/devtools/client/jsonview/converter-child.js#168 -
Received JSON data are parsed (using standard
parseJSON) here
https://searchfox.org/mozilla-central/rev/6bceafe72cad5d5752667b4b6bd595d3a4047ca3/devtools/client/jsonview/json-viewer.js#146-170
So, the conversion could be done along these lines.
Honza
Updated•6 years ago
|
Comment 3•6 years ago
|
||
But NDJSON is not JSON, it's a superset, so it needs a custom parser.
I don't think writing a custom parser is a good first bug.
Comment 4•6 years ago
|
||
I was hoping there is already an existing parser module we could reuse...
Removing the keyword.
Honza
Comment 5•6 years ago
|
||
Might it be useful to have more generic source formatting mechanisms, as we keep adding more for WebSocket frame inspection, Storage value inspection, etc.
This would be the library to include: https://www.npmjs.com/package/ndjson
Updated•3 years ago
|
Description
•