Open brandonmp opened 7 years ago
you can't write javascript objects directly to a file - instead use JSONStream.stringify()
I had to do something similar with this library and it worked well. The only thing is that JSONStram.stringify()
writes an array of objects, which wasn't an issue for me.
Here's what I would try:
// write all objects with a path that matches '/*/images/'
var writeStream = fs.createWriteStream('home-images.json')
var readStream = fs.createReadStream('homes.json')
readStream
.pipe(JSONStream.parse([true, 'images', {emitKey: true}]))
.pipe(JSONStream.stringify())
.pipe(writeStream)
Haven't worked too much with streams & having some trouble understanding this
API
--anyone have some good examples they can point to?my use case is pretty simple. I have a giant single-object
JSON
, ie,So, there are no arrays, but just a massive nested object.
I'd like to stream it in, parse it, and write the results to a new
JSON
.So far, this is what I've come up w/:
But as you may have guessed, this is just making it rain errors.