question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fetch-newline-delimited-json

See original GitHub issue

This proposal is to create a fetch-newline-delimited-json package who can be used to make a request to a newline-delimited-json service and provide some way of being notified with the stream of objects and its completion.

Option 1: A promise that returns a CanJS-style event emitter

var fetchNDJSON = require("fetch-newline-delimited-json");

fetchNDJSON("/api/todos.ndjson", {}).then(function(eventEmitter){
  eventEmitter.on("row", function(ev, row){
    
  });
  eventEmitter.on("end", function(ev){
    
  });
  eventEmitter.on("error", function(ev, error){
    
  });
})

Pros:

  • lightest weight for CanJS to implement

Considerations:

  • Promise tells us if connection was successful

Option 2: A promise that returns a Kefir stream:

var fetchNDJSON = require("fetch-newline-delimited-json");

fetchNDJSON("/api/todos.ndjson", {}).then(function(stream){
  stream.onValue(function(row){
    
  });
  stream.onError(function(error){
    
  });
  stream.onEnd(function(){
    
  });
})

Pros:

  • streams are nice because they more accurately represent a sequence of values.

Cons:

  • heavier weight

Implementation details

This should work like the following CSV example, but use JSON.parse:

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
justinbmeyercommented, Feb 20, 2017

@matthewp I thought about that, but I think response.body.pipeThrough isn’t available. Also, I don’t think TransferStreams are available. We might be able to provide our own pipeThrough that works with something that implements both the reader and writer spec.

0reactions
justinbmeyercommented, Feb 22, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

Fetch newline delimited json - JavaScript - SitePoint Forums
This function uses fetch to retrieve and process a stream of ndjson incrementally instead of parsing a potentially huge response all at once....
Read more >
How to parse a newline delimited JSON - Stack Overflow
I'm working with App Scripts to pull a JSON file from a GCS bucket. The data is stored as a newline delimited JSON...
Read more >
Newline Delimited JSON (ndjson) Format
DataWeave represents the Newline Delimited JSON format (ndjson) as an array of objects. Each line of the ndjson format is mapped to one...
Read more >
Newline delimited JSON is awesome | by Jaga Santagostino
Newline delimited JSON is awesome. The power of JSON without reading a whole JSON. Whats wrong with JSON? Nothing, JSON is a great ......
Read more >
mash/fetch-ndjson - GitHub
fetch -ndjson turns new line delimited JSON streaming responses retrieved using Fetch API into Generators that yield JSON - GitHub - mash/fetch-ndjson: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found