Skip to content

chkimes/json-stream-extract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-stream-extract

Extract specific JSON fields from a readable stream using limited allocations.

Usage

// myFile.json:
// {
//   "myField": "myValue",
//   "myOtherField": "myOtherValue"
// }

const stream = fs.createReadStream('myFile.json')
const minimal = await extract(stream, {
  myField: null
})
console.log(minimal)

// {
//   myField: 'myValue'
// }

Installation

https://www.npmjs.com/package/json-stream-extract

npm i json-stream-extract

Why would I use this?

This is useful for extracting specific small fields out of large JSON blobs without suffering the large allocations required from JSON.parse. Allocations are limited to only those necessary for creating the top-level field strings and for any values that are specified for extraction.

Performance

This is roughly 2-3x slower than JSON.parse, but the reduced allocations may make that trade-off worth the cost.

About

Extract specific JSON fields from a readable stream using limited allocations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published