Open Bug 1603986 Opened 6 years ago Updated 9 months ago

Support newline delimited JSON (NDJSON) with MIME type application/x-ndjson

Categories

(DevTools :: JSON Viewer, enhancement, P3)

enhancement

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 }]

Thanks for the report!

Agree, it makes sense to support application/x-ndjson

Honza

Priority: -- → P3

Some pointers to the source code for anyone interested in fixing this bug:

  1. 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

  2. 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

  3. 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

  4. 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

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.

I was hoping there is already an existing parser module we could reuse...
Removing the keyword.

Honza

Keywords: good-first-bug

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

See Also: → 1627339
Severity: normal → S3
Duplicate of this bug: 1713317
You need to log in before you can comment on or make changes to this bug.