Streams a JSON file from a local or remote location in chunks. Each intermediate chunk is passed as a DataFrame to the callback function.
danfo.streamJSON(filePath, callback, options)
Parameters
Type
Description
filePath
string
URL or local file path to CSV file.
callback
Function
Callback function to be called once the specifed rows are parsed into DataFrame.
options
object
Optional configuration object. We use the request library for reading remote json files, Hence all request parameters such as method, headers, are supported.
The streamJSON function streams a JSON file from a local or remote location in chunks. Each intermediate chunk is passed as a DataFrame to the callback function.
Stream JSON file from local path
constdfd=require("danfojs-node")constpath=require("path")constfilePath=path.join(process.cwd(),"raw_data","book_small.json");dfd.streamJSON(filePath, (df) => {if (df) {// Do any processing heredf.print(); }});
//Showing the last rows
...
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║ │ book_id │ title │ image_url │ authors ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 10 │ 32848471 │ Egomaniac │ https://images.… │ Vi Keeland ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝
╔════════════╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗
║ │ book_id │ title │ image_url │ authors ║
╟────────────┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢
║ 11 │ 33288638 │ Wait for It │ https://s.gr-as… │ Mariana Zapata ║
╚════════════╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝