fetch-newline-delimited-json
See original GitHub issueThis 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:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.Closing for https://github.com/canjs/can-ndjson-stream/issues/1